diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 4a4f96ee7c..100e001fc8 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -999,8 +999,9 @@ class Core { throw new IllegalArgumentException("self"); // De-classify - for (EntityMessage message : messages) - MessageClassifier.classify(message, target, context); + if (MessageClassifier.canClassify(folder.type)) + for (EntityMessage message : messages) + MessageClassifier.classify(message, false, context); IMAPFolder itarget = (IMAPFolder) istore.getFolder(target.name); @@ -1503,7 +1504,7 @@ class Core { parts.isPlainOnly(), HtmlHelper.getPreview(body), parts.getWarnings(message.warning)); - MessageClassifier.classify(message, null, context); + MessageClassifier.classify(message, true, context); if (body != null) EntityLog.log(context, "Operation body size=" + body.length()); @@ -3010,7 +3011,7 @@ class Core { parts.isPlainOnly(), HtmlHelper.getPreview(body), parts.getWarnings(message.warning)); - MessageClassifier.classify(message, null, context); + MessageClassifier.classify(message, true, context); if (!message.ui_hide) db.message().setMessageUiHide(message.id, false); @@ -3445,7 +3446,7 @@ class Core { parts.isPlainOnly(), HtmlHelper.getPreview(body), parts.getWarnings(message.warning)); - MessageClassifier.classify(message, null, context); + MessageClassifier.classify(message, true, context); if (stats != null && body != null) stats.content += body.length(); diff --git a/app/src/main/java/eu/faircode/email/MessageClassifier.java b/app/src/main/java/eu/faircode/email/MessageClassifier.java index 540863a112..0399805d2b 100644 --- a/app/src/main/java/eu/faircode/email/MessageClassifier.java +++ b/app/src/main/java/eu/faircode/email/MessageClassifier.java @@ -51,14 +51,11 @@ public class MessageClassifier { private static final double COMMON_WORD_FACTOR = 0.75; private static final double CHANCE_THRESHOLD = 2.0; - static void classify(EntityMessage message, EntityFolder target, Context context) { + static void classify(EntityMessage message, boolean added, Context context) { try { if (!isEnabled(context)) return; - if (target != null && !canClassify(target.type)) - return; - DB db = DB.getInstance(context); EntityFolder folder = db.folder().getFolder(message.folder); @@ -87,7 +84,7 @@ public class MessageClassifier { if (!wordClassFrequency.containsKey(account.id)) wordClassFrequency.put(account.id, new HashMap<>()); - String classified = classify(account.id, folder.name, text, target == null, context); + String classified = classify(account.id, folder.name, text, added, context); EntityLog.log(context, "Classifier" + " folder=" + folder.name + @@ -98,7 +95,7 @@ public class MessageClassifier { " re=" + message.auto_classified); Integer m = classMessages.get(account.id).get(folder.name); - if (target == null) { + if (added) { m = (m == null ? 1 : m + 1); classMessages.get(account.id).put(folder.name, m); } else { @@ -113,11 +110,11 @@ public class MessageClassifier { try { db.beginTransaction(); - EntityFolder f = db.folder().getFolderByName(account.id, classified); - if (f != null && !f.id.equals(folder.id) && f.auto_classify && - (EntityFolder.JUNK.equals(f.type) || ActivityBilling.isPro(context))) { + EntityFolder target = db.folder().getFolderByName(account.id, classified); + if (target != null && !target.id.equals(folder.id) && target.auto_classify && + (EntityFolder.JUNK.equals(target.type) || ActivityBilling.isPro(context))) { - EntityOperation.queue(context, message, EntityOperation.MOVE, f.id, false, true); + EntityOperation.queue(context, message, EntityOperation.MOVE, target.id, false, true); message.ui_hide = true; }