From fa97fa48e67cef1f911f78eb09768b226ea399d3 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 12 Aug 2018 19:11:53 +0000 Subject: [PATCH] Sent fixes --- .../main/java/eu/faircode/email/DaoMessage.java | 6 +++++- .../eu/faircode/email/ServiceSynchronize.java | 16 ++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 0dad3f42..018c798c 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -80,7 +80,11 @@ public interface DaoMessage { @Query("SELECT * FROM message WHERE folder = :folder AND uid = :uid") EntityMessage getMessageByUid(long folder, long uid); - @Query("SELECT * FROM message WHERE msgid = :msgid") + @Query("SELECT message.* FROM message" + + " JOIN folder ON folder.id = message.folder" + + " WHERE msgid = :msgid" + + " AND folder.type <> '" + EntityFolder.INBOX + "'" + + " AND folder.type <> '" + EntityFolder.ARCHIVE + "'") EntityMessage getMessageByMsgId(String msgid); @Query("SELECT message.* FROM message" + diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 8ddf426a..227aa97c 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -970,8 +970,8 @@ public class ServiceSynchronize extends LifecycleService { message.ui_seen = true; db.message().updateMessage(message); - if (sent != null) - EntityOperation.queue(db, message, EntityOperation.ADD); // Could already exist + //if (sent != null) + // EntityOperation.queue(db, message, EntityOperation.ADD); // Could already exist db.setTransactionSuccessful(); } finally { @@ -1193,14 +1193,15 @@ public class ServiceSynchronize extends LifecycleService { // Find message by Message-ID (slow, headers required) // - messages in inbox have same id as message sent to self // - messages in archive have same id as original - if (message == null && - !EntityFolder.SENT.equals(folder.type) && - !EntityFolder.ARCHIVE.equals(folder.type)) { + if (message == null) { // Will fetch headers within database transaction String msgid = imessage.getMessageID(); message = db.message().getMessageByMsgId(msgid); if (message != null) { - if (message.folder == folder.id || EntityFolder.OUTBOX.equals(folder.type)) { + 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; @@ -1243,8 +1244,7 @@ public class ServiceSynchronize extends LifecycleService { message.folder = folder.id; message.uid = uid; - if (!EntityFolder.SENT.equals(folder.type) && - !EntityFolder.ARCHIVE.equals(folder.type)) { + if (!EntityFolder.ARCHIVE.equals(folder.type)) { message.msgid = helper.getMessageID(); if (TextUtils.isEmpty(message.msgid)) Log.w(Helper.TAG, "No Message-ID id=" + message.id + " uid=" + message.uid);