mirror of https://github.com/M66B/FairEmail.git
Added async download of POP3 attachments
This commit is contained in:
parent
97e033ab03
commit
e5ba419e75
|
@ -375,13 +375,16 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
|||
db.beginTransaction();
|
||||
|
||||
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;
|
||||
|
||||
if (!"connected".equals(account.state) && !account.isTransient(context))
|
||||
reload = account.id;
|
||||
|
||||
|
|
|
@ -230,13 +230,16 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
|||
db.beginTransaction();
|
||||
|
||||
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;
|
||||
|
||||
if (!"connected".equals(account.state) && !account.isTransient(context))
|
||||
reload = account.id;
|
||||
|
||||
|
|
|
@ -4984,7 +4984,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
db.beginTransaction();
|
||||
|
||||
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;
|
||||
|
||||
for (EntityAttachment attachment : db.attachment().getAttachments(message.id))
|
||||
|
|
|
@ -441,6 +441,10 @@ class Core {
|
|||
onRaw(context, jargs, folder, message, (POP3Store) istore, (POP3Folder) ifolder);
|
||||
break;
|
||||
|
||||
case EntityOperation.ATTACHMENT:
|
||||
onAttachment(context, jargs, folder, message, (POP3Folder) ifolder, (POP3Store) istore);
|
||||
break;
|
||||
|
||||
case EntityOperation.SYNC:
|
||||
Helper.gc();
|
||||
onSynchronizeMessages(context, jargs, account, folder, (POP3Folder) ifolder, (POP3Store) istore, state);
|
||||
|
@ -2196,6 +2200,35 @@ class Core {
|
|||
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) {
|
||||
// POP3
|
||||
EntityContact.received(context, account, folder, message);
|
||||
|
@ -3357,9 +3390,13 @@ class Core {
|
|||
message.preview,
|
||||
parts.getWarnings(message.warning));
|
||||
|
||||
for (EntityAttachment attachment : parts.getAttachments())
|
||||
if (attachment.subsequence == null)
|
||||
parts.downloadAttachment(context, attachment);
|
||||
try {
|
||||
for (EntityAttachment attachment : parts.getAttachments())
|
||||
if (attachment.subsequence == null)
|
||||
parts.downloadAttachment(context, attachment);
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
|
||||
if (download_eml)
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue