From 76557a7345e526d31d7ebac9412952f1e3c7c450 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 16 Aug 2018 17:50:01 +0000 Subject: [PATCH] Fixed handling known messages Fixes #41 --- .../java/eu/faircode/email/DaoMessage.java | 2 +- .../eu/faircode/email/ServiceSynchronize.java | 23 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index fd1f4fe6..2f81ce20 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -85,7 +85,7 @@ public interface DaoMessage { " WHERE msgid = :msgid" + " AND folder.type <> '" + EntityFolder.INBOX + "'" + " AND folder.type <> '" + EntityFolder.ARCHIVE + "'") - EntityMessage getMessageByMsgId(String msgid); + List getMessageByMsgId(String msgid); @Query("SELECT message.* FROM message" + " JOIN folder ON folder.id = message.folder" + diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 366afb4a..10a9e3ae 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -1222,19 +1222,18 @@ public class ServiceSynchronize extends LifecycleService { if (message == null) { // Will fetch headers within database transaction String msgid = helper.getMessageID(); - message = db.message().getMessageByMsgId(msgid); - if (message != null) { - EntityFolder mfolder = db.folder().getFolder(message.folder); - Log.i(Helper.TAG, folder.name + " found as id=" + message.id + - " folder=" + mfolder.type + ":" + message.folder + "/" + folder.type + ":" + folder.id); - if (message.folder.equals(folder.id) || EntityFolder.OUTBOX.equals(mfolder.type)) { - Log.i(Helper.TAG, folder.name + " found as id=" + message.id + " uid=" + message.uid + " msgid=" + msgid); - message.folder = folder.id; - message.uid = uid; - db.message().updateMessage(message); + for (EntityMessage dup : db.message().getMessageByMsgId(msgid)) { + EntityFolder dfolder = db.folder().getFolder(dup.folder); + Log.i(Helper.TAG, folder.name + " found as id=" + dup.id + + " folder=" + dfolder.type + ":" + dup.folder + "/" + folder.type + ":" + folder.id); + if (dup.folder.equals(folder.id) || EntityFolder.OUTBOX.equals(dfolder.type)) { + Log.i(Helper.TAG, folder.name + " found as id=" + dup.id + " uid=" + dup.uid + " msgid=" + msgid); + dup.folder = folder.id; + dup.uid = uid; + db.message().updateMessage(dup); + message = dup; result = -1; - } else - message = null; + } } }