From c471727f3cc86f1c896fa337be621b1716f0298a Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 16 Aug 2020 16:24:50 +0200 Subject: [PATCH] Fixed duplicate signature images --- .../eu/faircode/email/FragmentCompose.java | 2 +- .../java/eu/faircode/email/MessageHelper.java | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 10158be760..13ad894be2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -4449,7 +4449,7 @@ public class FragmentCompose extends FragmentBase { if (identity.unicode) props.put("mail.mime.allowutf8", "true"); Session isession = Session.getInstance(props, null); - Message imessage = MessageHelper.from(context, draft, identity, isession, true); + Message imessage = MessageHelper.from(context, draft, identity, isession, false); File file = draft.getRawFile(context); try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index a6c84ca5fb..9458d8cebe 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -557,19 +557,18 @@ public class MessageHelper { Document document = JsoupEx.parse(message.getFile(context)); // When sending message - if (identity != null) { - if (send) { - for (Element child : document.body().children()) - if (!TextUtils.isEmpty(child.text()) && - TextUtils.isEmpty(child.attr("fairemail"))) { - String style = HtmlHelper.mergeStyles( - "font-family:" + compose_font, child.attr("style")); - child.attr("style", style); - } - document.select("div[fairemail=signature]").removeAttr("fairemail"); - document.select("div[fairemail=reference]").removeAttr("fairemail"); - } + if (identity != null && send) { + for (Element child : document.body().children()) + if (!TextUtils.isEmpty(child.text()) && + TextUtils.isEmpty(child.attr("fairemail"))) { + String style = HtmlHelper.mergeStyles( + "font-family:" + compose_font, child.attr("style")); + child.attr("style", style); + } + document.select("div[fairemail=signature]").removeAttr("fairemail"); + document.select("div[fairemail=reference]").removeAttr("fairemail"); + boolean save = false; DB db = DB.getInstance(context); try { db.beginTransaction(); @@ -615,6 +614,7 @@ public class MessageHelper { attachments.add(attachment); img.attr("src", "cid:" + cid); + save = true; } db.setTransactionSuccessful(); @@ -623,6 +623,9 @@ public class MessageHelper { } finally { db.endTransaction(); } + + if (save) + Helper.writeText(message.getFile(context), document.html()); } // multipart/mixed