From 86b55996f44683bf87a48d9b71c9b1bb84db9e65 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 14 May 2019 10:40:48 +0200 Subject: [PATCH] Small fix --- app/src/main/java/eu/faircode/email/Core.java | 40 +++++++++++-------- .../eu/faircode/email/EntityOperation.java | 3 +- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 9184910e8b..da979a07b6 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -438,10 +438,22 @@ class Core { // Add message DB db = DB.getInstance(context); + // Get arguments + Long tmpid = (jargs.length() > 0 && !jargs.isNull(0) ? jargs.getLong(0) : null); + boolean autoread = (jargs.length() > 1 && jargs.getBoolean(1)); + boolean across = (jargs.length() > 2 && jargs.getBoolean(2)); + try { if (TextUtils.isEmpty(message.msgid)) throw new IllegalArgumentException("Message ID missing"); + if (EntityFolder.DRAFTS.equals(folder.type) && + !folder.id.equals(message.folder) && + !across) { + Log.i("Drafts moved folder=" + message.folder); + return; + } + // Delete previous message(s) with same ID if (folder.id.equals(message.folder)) { // Prevent adding/deleting message @@ -483,14 +495,10 @@ class Core { } // Handle auto read - boolean autoread = false; - if (jargs.length() > 1) { - autoread = jargs.getBoolean(1); - if (ifolder.getPermanentFlags().contains(Flags.Flag.SEEN)) { - if (autoread && !imessage.isSet(Flags.Flag.SEEN)) { - Log.i(folder.name + " autoread"); - imessage.setFlag(Flags.Flag.SEEN, true); - } + if (ifolder.getPermanentFlags().contains(Flags.Flag.SEEN)) { + if (autoread && !imessage.isSet(Flags.Flag.SEEN)) { + Log.i(folder.name + " autoread"); + imessage.setFlag(Flags.Flag.SEEN, true); } } @@ -532,16 +540,16 @@ class Core { if (folder.id.equals(message.folder)) { Log.i(folder.name + " Setting id=" + message.id + " uid=" + uid); db.message().setMessageUid(message.id, uid); - } else { - // Cross account move - if (jargs.length() > 0 && !jargs.isNull(0)) { - long tmpid = jargs.getLong(0); - Log.i(folder.name + " Setting id=" + tmpid + " (tmp) appended uid=" + uid); - db.message().setMessageUid(tmpid, uid); - } + } else try { db.beginTransaction(); + // Cross account move + if (tmpid != null) { + Log.i(folder.name + " Setting id=" + tmpid + " (tmp) appended uid=" + uid); + db.message().setMessageUid(tmpid, uid); + } + // Mark source read if (autoread) { Log.i(folder.name + " queuing SEEN id=" + message.id); @@ -556,7 +564,6 @@ class Core { } finally { db.endTransaction(); } - } } catch (Throwable ex) { if (folder.id.equals(message.folder)) db.message().setMessageUid(message.id, message.uid); @@ -664,6 +671,7 @@ class Core { // Cross account move long target = jargs.getLong(2); jargs.remove(2); + jargs.put(2, true); // cross account Log.i(folder.name + " queuing ADD id=" + message.id + ":" + target); EntityOperation operation = new EntityOperation(); diff --git a/app/src/main/java/eu/faircode/email/EntityOperation.java b/app/src/main/java/eu/faircode/email/EntityOperation.java index 22d8239a70..e0b0a2ba17 100644 --- a/app/src/main/java/eu/faircode/email/EntityOperation.java +++ b/app/src/main/java/eu/faircode/email/EntityOperation.java @@ -184,16 +184,17 @@ public class EntityOperation { EntityAttachment.copy(context, message.id, tmpid); } - // Cross account move if (source.account.equals(target.account)) jargs.put(2, tmpid); // Can be null else { + // Cross account move if (message.raw != null && message.raw) { name = ADD; folder = target.id; jargs = new JSONArray(); jargs.put(0, tmpid); // Can be null jargs.put(1, autoread); + jargs.put(2, true); // Cross account } else { name = RAW; jargs = new JSONArray();