From afb25fbf53758e9343646ec2dce7cf0539554c13 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 27 Dec 2021 13:57:59 +0100 Subject: [PATCH] Fixed removing inline images on reply/forward --- .../eu/faircode/email/FragmentCompose.java | 60 +++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index c27e21f0d1..4c1d2dad31 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -5526,37 +5526,6 @@ public class FragmentCompose extends FragmentBase { if (TextUtils.isEmpty(extra)) extra = null; - if (action == R.id.action_send) { - if (draft.plain_only == null || !draft.plain_only) { - // Remove unused inline images - List cids = new ArrayList<>(); - Document d = JsoupEx.parse(body); - for (Element element : d.select("img")) { - String src = element.attr("src"); - if (src.startsWith("cid:")) - cids.add("<" + src.substring(4) + ">"); - } - - for (EntityAttachment attachment : new ArrayList<>(attachments)) - if (attachment.isInline() && attachment.isImage() && - attachment.cid != null && !cids.contains(attachment.cid)) { - Log.i("Removing unused inline attachment cid=" + attachment.cid); - attachments.remove(attachment); - db.attachment().deleteAttachment(attachment.id); - dirty = true; - } - } else { - // Convert inline images to attachments - for (EntityAttachment attachment : new ArrayList<>(attachments)) - if (attachment.isInline() && attachment.isImage()) { - Log.i("Converting to attachment cid=" + attachment.cid); - attachment.disposition = Part.ATTACHMENT; - db.attachment().setDisposition(attachment.id, attachment.disposition); - dirty = true; - } - } - } - List eparts = new ArrayList<>(); for (EntityAttachment attachment : attachments) if (attachment.available) @@ -5713,6 +5682,35 @@ public class FragmentCompose extends FragmentBase { " action=" + getActionName(action)); dirty = true; + } else if (action == R.id.action_send) { + if (draft.plain_only == null || !draft.plain_only) { + // Remove unused inline images + List cids = new ArrayList<>(); + Document d = JsoupEx.parse(body); + for (Element element : d.select("img")) { + String src = element.attr("src"); + if (src.startsWith("cid:")) + cids.add("<" + src.substring(4) + ">"); + } + + for (EntityAttachment attachment : new ArrayList<>(attachments)) + if (attachment.isInline() && attachment.isImage() && + attachment.cid != null && !cids.contains(attachment.cid)) { + Log.i("Removing unused inline attachment cid=" + attachment.cid); + attachments.remove(attachment); + db.attachment().deleteAttachment(attachment.id); + dirty = true; + } + } else { + // Convert inline images to attachments + for (EntityAttachment attachment : new ArrayList<>(attachments)) + if (attachment.isInline() && attachment.isImage()) { + Log.i("Converting to attachment cid=" + attachment.cid); + attachment.disposition = Part.ATTACHMENT; + db.attachment().setDisposition(attachment.id, attachment.disposition); + dirty = true; + } + } } Helper.writeText(draft.getFile(context), body);