Added async download of POP3 attachments

pull/209/head
M66B 2 years ago
parent 97e033ab03
commit e5ba419e75

@ -375,13 +375,16 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
db.beginTransaction(); db.beginTransaction();
EntityMessage message = db.message().getMessage(mid); EntityMessage message = db.message().getMessage(mid);
if (message == null || message.uid == null) if (message == null)
return null; return null;
EntityAccount account = db.account().getAccount(message.account); EntityAccount account = db.account().getAccount(message.account);
if (account == null) if (account == null)
return null; return null;
if (account.protocol == EntityAccount.TYPE_IMAP && message.uid == null)
return null;
if (!"connected".equals(account.state) && !account.isTransient(context)) if (!"connected".equals(account.state) && !account.isTransient(context))
reload = account.id; reload = account.id;

@ -230,13 +230,16 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
db.beginTransaction(); db.beginTransaction();
EntityMessage message = db.message().getMessage(mid); EntityMessage message = db.message().getMessage(mid);
if (message == null || message.uid == null) if (message == null)
return null; return null;
EntityAccount account = db.account().getAccount(message.account); EntityAccount account = db.account().getAccount(message.account);
if (account == null) if (account == null)
return null; return null;
if (account.protocol == EntityAccount.TYPE_IMAP && message.uid == null)
return null;
if (!"connected".equals(account.state) && !account.isTransient(context)) if (!"connected".equals(account.state) && !account.isTransient(context))
reload = account.id; reload = account.id;

@ -4984,7 +4984,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.beginTransaction(); db.beginTransaction();
EntityMessage message = db.message().getMessage(mid); EntityMessage message = db.message().getMessage(mid);
if (message == null || message.uid == null) if (message == null)
return null;
EntityAccount account = db.account().getAccount(message.account);
if (account == null)
return null;
if (account.protocol == EntityAccount.TYPE_IMAP && message.uid == null)
return null; return null;
for (EntityAttachment attachment : db.attachment().getAttachments(message.id)) for (EntityAttachment attachment : db.attachment().getAttachments(message.id))

@ -441,6 +441,10 @@ class Core {
onRaw(context, jargs, folder, message, (POP3Store) istore, (POP3Folder) ifolder); onRaw(context, jargs, folder, message, (POP3Store) istore, (POP3Folder) ifolder);
break; break;
case EntityOperation.ATTACHMENT:
onAttachment(context, jargs, folder, message, (POP3Folder) ifolder, (POP3Store) istore);
break;
case EntityOperation.SYNC: case EntityOperation.SYNC:
Helper.gc(); Helper.gc();
onSynchronizeMessages(context, jargs, account, folder, (POP3Folder) ifolder, (POP3Store) istore, state); onSynchronizeMessages(context, jargs, account, folder, (POP3Folder) ifolder, (POP3Store) istore, state);
@ -2196,6 +2200,35 @@ class Core {
EntityLog.log(context, "Operation attachment size=" + attachment.size); EntityLog.log(context, "Operation attachment size=" + attachment.size);
} }
private static void onAttachment(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, POP3Folder ifolder, POP3Store istore) throws JSONException, MessagingException, IOException {
long id = jargs.getLong(0);
if (!EntityFolder.INBOX.equals(folder.type))
throw new IllegalArgumentException("Not INBOX");
DB db = DB.getInstance(context);
EntityAttachment attachment = db.attachment().getAttachment(id);
if (attachment == null)
throw new IllegalArgumentException("Local attachment not found");
if (attachment.subsequence != null)
throw new IllegalArgumentException("Download of sub attachment");
if (attachment.available)
return;
Map<EntityMessage, Message> map = findMessages(context, folder, Arrays.asList(message), istore, ifolder);
if (map.size() == 0)
throw new MessageRemovedException("Message not found");
MessageHelper helper = new MessageHelper((MimeMessage) map.entrySet().iterator().next().getValue(), context);
MessageHelper.MessageParts parts = helper.getMessageParts();
// Download attachment
parts.downloadAttachment(context, attachment);
if (attachment.size != null)
EntityLog.log(context, "Operation attachment size=" + attachment.size);
}
private static void onExists(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message) { private static void onExists(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message) {
// POP3 // POP3
EntityContact.received(context, account, folder, message); EntityContact.received(context, account, folder, message);
@ -3357,9 +3390,13 @@ class Core {
message.preview, message.preview,
parts.getWarnings(message.warning)); parts.getWarnings(message.warning));
for (EntityAttachment attachment : parts.getAttachments()) try {
if (attachment.subsequence == null) for (EntityAttachment attachment : parts.getAttachments())
parts.downloadAttachment(context, attachment); if (attachment.subsequence == null)
parts.downloadAttachment(context, attachment);
} catch (Throwable ex) {
Log.w(ex);
}
if (download_eml) if (download_eml)
try { try {

Loading…
Cancel
Save