From f26bc4e27a5d000440efa4b61bf60f32f41f7475 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 8 Dec 2021 16:29:39 +0100 Subject: [PATCH] Check inline images earlier --- .../eu/faircode/email/FragmentCompose.java | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index a1c551fda3..8b3e22de20 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -5512,6 +5512,37 @@ 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; + } + } + } + int available = 0; List eparts = new ArrayList<>(); for (EntityAttachment attachment : attachments) @@ -5916,32 +5947,6 @@ public class FragmentCompose extends FragmentBase { } } 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); - db.attachment().deleteAttachment(attachment.id); - } - } 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); - } - } - // Delete draft (cannot move to outbox) EntityOperation.queue(context, draft, EntityOperation.DELETE);