From 35e24c590e8f486b7645fdd42e1bab33c147f3e2 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 13 Jun 2019 12:41:50 +0200 Subject: [PATCH] Run rules on added messages --- app/src/main/java/eu/faircode/email/Core.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index ccd814a555..2a9f41cf4b 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -546,17 +546,23 @@ class Core { Log.i(folder.name + " appended id=" + message.id + " uid=" + uid); - if (folder.id.equals(message.folder)) { - Log.i(folder.name + " Setting id=" + message.id + " uid=" + uid); - db.message().setMessageUid(message.id, uid); - } else - try { - db.beginTransaction(); + try { + db.beginTransaction(); + List rules = db.rule().getEnabledRules(folder.id); + + if (folder.id.equals(message.folder)) { + Log.i(folder.name + " Setting id=" + message.id + " uid=" + uid); + db.message().setMessageUid(message.id, uid); + + runRules(context, imessage, message, rules); + } else { // Cross account move if (tmpid != null) { Log.i(folder.name + " Setting id=" + tmpid + " (tmp) appended uid=" + uid); db.message().setMessageUid(tmpid, uid); + + runRules(context, imessage, db.message().getMessage(tmpid), rules); } // Mark source read @@ -568,11 +574,12 @@ class Core { // Delete source Log.i(folder.name + " queuing DELETE id=" + message.id); EntityOperation.queue(context, message, EntityOperation.DELETE); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); } + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } } catch (Throwable ex) { if (folder.id.equals(message.folder)) db.message().setMessageUid(message.id, message.uid); @@ -1540,7 +1547,7 @@ class Core { } } - private static void runRules(Context context, IMAPMessage imessage, EntityMessage message, List rules) { + private static void runRules(Context context, Message imessage, EntityMessage message, List rules) { if (!Helper.isPro(context)) return;