From cd41d6812ac627471201e1c3f63a2f0b96048611 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 14 Sep 2018 06:13:46 +0000 Subject: [PATCH] Forward downloaded attachments Fixes #33 --- .../eu/faircode/email/FragmentCompose.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 378d0682..fdb86e03 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -784,7 +784,7 @@ public class FragmentCompose extends FragmentEx { draft = new EntityMessage(); draft.account = account.id; draft.folder = drafts.id; - draft.msgid = EntityMessage.generateMessageId(); // for multiple appends + draft.msgid = EntityMessage.generateMessageId(); if (ref == null) { try { @@ -888,10 +888,32 @@ public class FragmentCompose extends FragmentEx { draft.id = db.message().insertMessage(draft); draft.write(context, body == null ? "" : body); - ArrayList uris = args.getParcelableArrayList("attachments"); - if (uris != null) - for (Uri uri : uris) - addAttachment(context, draft.id, uri, false); + if ("new".equals(action)) { + ArrayList uris = args.getParcelableArrayList("attachments"); + if (uris != null) + for (Uri uri : uris) + addAttachment(context, draft.id, uri, false); + } else if ("forward".equals(action)) { + int sequence = 0; + List attachments = db.attachment().getAttachments(ref.id); + for (EntityAttachment attachment : attachments) + if (attachment.available) { + EntityAttachment copy = new EntityAttachment(); + copy.message = draft.id; + copy.sequence = ++sequence; + copy.name = attachment.name; + copy.type = attachment.type; + copy.cid = attachment.cid; + copy.size = attachment.size; + copy.progress = attachment.progress; + copy.available = attachment.available; + copy.id = db.attachment().insertAttachment(copy); + + File source = EntityAttachment.getFile(context, attachment.id); + File target = EntityAttachment.getFile(context, copy.id); + Helper.copy(source, target); + } + } EntityOperation.queue(db, draft, EntityOperation.ADD);