diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index a10d3d86f7..b9851e21d3 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -170,10 +170,9 @@ public interface DaoMessage { @Query("SELECT message.* FROM message" + " JOIN folder ON folder.id = message.folder" + " WHERE message.account = :account" + - " AND (message.msgid = :msgid" + - " OR message.msgid = :reference)" + + " AND message.msgid = :msgid" + " AND ui_found = :found") - List getMessageByMsgId(long account, String msgid, String reference, boolean found); + List getMessageByMsgId(long account, String msgid, boolean found); @Query("SELECT * FROM message" + " WHERE folder = :folder" + diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index bc2e43bf21..5ee6ee00c3 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -187,6 +187,7 @@ public class MessageHelper { imessage.addHeader("References", (replying.references == null ? "" : replying.references + " ") + replying.msgid); } + imessage.addHeader("X-FairEmail-ID", message.msgid); imessage.addHeader("X-FairEmail-Thread", message.thread); imessage.setFlag(Flags.Flag.SEEN, message.seen); @@ -368,6 +369,11 @@ public class MessageHelper { } String getMessageID() throws MessagingException { + // Outlook outbox -> sent + String[] xID = imessage.getHeader("X-FairEmail-ID"); + if (xID != null && xID.length > 0) + return xID[0]; + return imessage.getHeader("Message-ID", null); } @@ -385,6 +391,7 @@ public class MessageHelper { } String getThreadId(long uid) throws MessagingException { + // Some providers break references when moving messages String[] xThread = imessage.getHeader("X-FairEmail-Thread"); if (xThread != null && xThread.length > 0) return xThread[0]; @@ -392,6 +399,7 @@ public class MessageHelper { for (String ref : getReferences()) if (!TextUtils.isEmpty(ref)) return ref; + String msgid = getMessageID(); return (TextUtils.isEmpty(msgid) ? Long.toString(uid) : msgid); } diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 67f23a641a..7286e0061f 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -2021,9 +2021,8 @@ public class ServiceSynchronize extends LifecycleService { // Will fetch headers within database transaction String msgid = helper.getMessageID(); String[] refs = helper.getReferences(); - String reference = (refs.length == 1 && refs[0].indexOf(BuildConfig.APPLICATION_ID) > 0 ? refs[0] : msgid); - Log.i(Helper.TAG, "Searching for " + msgid + " / " + reference); - for (EntityMessage dup : db.message().getMessageByMsgId(folder.account, msgid, reference, found)) { + Log.i(Helper.TAG, "Searching for " + msgid); + for (EntityMessage dup : db.message().getMessageByMsgId(folder.account, msgid, found)) { EntityFolder dfolder = db.folder().getFolder(dup.folder); boolean outbox = EntityFolder.OUTBOX.equals(dfolder.type); Log.i(Helper.TAG, folder.name + " found as id=" + dup.id + "/" + dup.uid +