Fixed decrypting attachments

This commit is contained in:
M66B 2019-03-10 20:26:56 +00:00
parent d1c1ebfe01
commit 759cde6bda
3 changed files with 12 additions and 7 deletions

View File

@ -1312,11 +1312,14 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
db.attachment().deleteAttachment(a.id);
// Add decrypted attachments
attachments = parts.getAttachments();
int sequence = db.attachment().getAttachmentSequence(id);
for (EntityAttachment a : parts.getAttachments()) {
for (int index = 0; index < attachments.size(); index++) {
EntityAttachment a = attachments.get(index);
a.message = id;
a.sequence = ++sequence;
a.id = db.attachment().insertAttachment(a);
parts.downloadAttachment(context, index, a.id);
}
db.message().setMessageStored(id, new Date().getTime());

View File

@ -675,7 +675,7 @@ class Core {
// Download attachment
MessageHelper helper = new MessageHelper((MimeMessage) imessage);
MessageHelper.MessageParts parts = helper.getMessageParts();
parts.downloadAttachment(context, db, attachment.id, sequence);
parts.downloadAttachment(context, sequence - 1, attachment.id);
}
private static long append(IMAPStore istore, IMAPFolder ifolder, MimeMessage imessage) throws MessagingException {
@ -1411,7 +1411,7 @@ class Core {
for (EntityAttachment attachment : attachments)
if (!attachment.available)
if (!metered || (attachment.size != null && attachment.size < maxSize))
if (!parts.downloadAttachment(context, db, attachment.id, attachment.sequence))
if (!parts.downloadAttachment(context, attachment.sequence - 1, attachment.id))
break;
}
}

View File

@ -691,18 +691,20 @@ public class MessageHelper {
return result;
}
boolean downloadAttachment(Context context, DB db, long id, int sequence) throws IOException {
boolean downloadAttachment(Context context, int index, long id) {
Log.i("downloading attchment id=" + id + " seq=" + index);
// Attachments of drafts might not have been uploaded yet
if (sequence > attachments.size()) {
Log.w("Attachment unavailable sequence=" + sequence + " size=" + attachments.size());
if (index > attachments.size()) {
Log.w("Attachment unavailable sequence=" + index + " size=" + attachments.size());
return false;
}
// Get data
AttachmentPart apart = attachments.get(sequence - 1);
AttachmentPart apart = attachments.get(index);
File file = EntityAttachment.getFile(context, id);
// Download attachment
DB db = DB.getInstance(context);
db.attachment().setProgress(id, null);
try (InputStream is = apart.part.getInputStream()) {
long size = 0;