From 20047afc4141834d723ec7ea09c5ac3480ac92f3 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 30 Aug 2022 18:42:22 +0200 Subject: [PATCH] Improved late draft logic --- app/src/main/java/eu/faircode/email/Core.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 47f37c9538..627220b3de 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -4055,15 +4055,26 @@ class Core { message = dup; process = true; - } else if (dup.uid < uid && EntityFolder.DRAFTS.equals(folder.type)) { + } else if (msgid != null && EntityFolder.DRAFTS.equals(folder.type)) { try { - Message existing = ifolder.getMessageByUID(dup.uid); - Log.e(folder.name + " late draft host=" + account.host + - " uid=" + dup.uid + "<" + uid + " found=" + (existing != null)); - if (existing != null) { - existing.setFlag(Flags.Flag.DELETED, true); - expunge(context, ifolder, Arrays.asList(existing)); - db.message().setMessageUiHide(dup.id, true); + if (dup.uid < uid) { + MimeMessage existing = (MimeMessage) ifolder.getMessageByUID(dup.uid); + if (existing != null && + msgid.equals(existing.getHeader(MessageHelper.HEADER_CORRELATION_ID, null))) { + Log.e(folder.name + " late draft" + + " host=" + account.host + " uid=" + dup.uid + "<" + uid); + existing.setFlag(Flags.Flag.DELETED, true); + expunge(context, ifolder, Arrays.asList(existing)); + db.message().setMessageUiHide(dup.id, true); + } + } else if (dup.uid > uid) { + if (msgid.equals(imessage.getHeader(MessageHelper.HEADER_CORRELATION_ID, null))) { + Log.e(folder.name + " late draft" + + " host=" + account.host + " uid=" + dup.uid + ">" + uid); + imessage.setFlag(Flags.Flag.DELETED, true); + expunge(context, ifolder, Arrays.asList(imessage)); + return null; + } } } catch (Throwable ex) { Log.e(ex);