diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 146b3210c1..187ecfe4aa 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1000,7 +1000,7 @@ class Core { // De-classify for (EntityMessage message : messages) - MessageClassifier.classify(message, false, context); + MessageClassifier.classify(message, target, context); IMAPFolder itarget = (IMAPFolder) istore.getFolder(target.name); @@ -1503,7 +1503,7 @@ class Core { parts.isPlainOnly(), HtmlHelper.getPreview(body), parts.getWarnings(message.warning)); - MessageClassifier.classify(message, true, context); + MessageClassifier.classify(message, null, context); if (body != null) EntityLog.log(context, "Operation body size=" + body.length()); @@ -3007,7 +3007,7 @@ class Core { parts.isPlainOnly(), HtmlHelper.getPreview(body), parts.getWarnings(message.warning)); - MessageClassifier.classify(message, true, context); + MessageClassifier.classify(message, null, context); if (stats != null && body != null) stats.content += body.length(); @@ -3135,7 +3135,7 @@ class Core { if (process) { updateContactInfo(context, folder, message); - MessageClassifier.classify(message, true, context); + MessageClassifier.classify(message, null, context); } else Log.d(folder.name + " unchanged uid=" + uid); } @@ -3437,7 +3437,7 @@ class Core { parts.isPlainOnly(), HtmlHelper.getPreview(body), parts.getWarnings(message.warning)); - MessageClassifier.classify(message, true, context); + MessageClassifier.classify(message, null, context); if (stats != null && body != null) stats.content += body.length(); diff --git a/app/src/main/java/eu/faircode/email/FragmentFolder.java b/app/src/main/java/eu/faircode/email/FragmentFolder.java index cf65b19c59..e598de5656 100644 --- a/app/src/main/java/eu/faircode/email/FragmentFolder.java +++ b/app/src/main/java/eu/faircode/email/FragmentFolder.java @@ -184,8 +184,6 @@ public class FragmentFolder extends FragmentBase { } }); - cbAutoClassify.setVisibility(MessageClassifier.isEnabled(getContext()) ? View.VISIBLE : View.GONE); - btnInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -226,6 +224,7 @@ public class FragmentFolder extends FragmentBase { grpImap.setVisibility(imap ? View.VISIBLE : View.GONE); tvParent.setText(parent); grpParent.setVisibility(parent == null ? View.GONE : View.VISIBLE); + cbAutoClassify.setVisibility(View.GONE); grpAutoDelete.setVisibility(View.GONE); btnSave.setEnabled(false); pbSave.setVisibility(View.GONE); @@ -325,6 +324,9 @@ public class FragmentFolder extends FragmentBase { tvPoll.setEnabled(cbSynchronize.isChecked() && always); grpPoll.setVisibility(imap && cbPoll.isEnabled() && cbPoll.isChecked() ? View.VISIBLE : View.GONE); cbAutoClassify.setEnabled(cbDownload.isChecked()); + cbAutoClassify.setVisibility(MessageClassifier.isEnabled(getContext()) && + (folder == null || MessageClassifier.canClassify(folder.type)) + ? View.VISIBLE : View.GONE); etKeepDays.setEnabled(!cbKeepAll.isChecked()); cbAutoDelete.setEnabled(!cbKeepAll.isChecked()); btnSave.setEnabled(true); diff --git a/app/src/main/java/eu/faircode/email/MessageClassifier.java b/app/src/main/java/eu/faircode/email/MessageClassifier.java index fd039db595..e37c83dcf3 100644 --- a/app/src/main/java/eu/faircode/email/MessageClassifier.java +++ b/app/src/main/java/eu/faircode/email/MessageClassifier.java @@ -49,7 +49,7 @@ 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, boolean added, Context context) { + static void classify(EntityMessage message, EntityFolder target, Context context) { if (!isEnabled(context)) return; @@ -59,6 +59,9 @@ public class MessageClassifier { Log.e(ex); } + if (target != null && !canClassify(target.type)) + return; + DB db = DB.getInstance(context); EntityFolder folder = db.folder().getFolder(message.folder); @@ -69,10 +72,7 @@ public class MessageClassifier { if (account == null) return; - if (!EntityFolder.INBOX.equals(folder.type) && - !EntityFolder.JUNK.equals(folder.type) && - !EntityFolder.USER.equals(folder.type) && - !(EntityFolder.ARCHIVE.equals(folder.type) && !account.isGmail())) + if (!canClassify(folder.type)) return; File file = message.getFile(context); @@ -95,10 +95,10 @@ public class MessageClassifier { if (!wordClassFrequency.containsKey(account.id)) wordClassFrequency.put(account.id, new HashMap<>()); - String classified = classify(account.id, folder.name, text, added); + String classified = classify(account.id, folder.name, text, target == null); Integer m = classMessages.get(account.id).get(folder.name); - if (added) { + if (target == null) { m = (m == null ? 1 : m + 1); classMessages.get(account.id).put(folder.name, m); } else { @@ -309,6 +309,11 @@ public class MessageClassifier { return prefs.getBoolean("classify", BuildConfig.DEBUG); } + static boolean canClassify(String folderType) { + return EntityFolder.INBOX.equals(folderType) || + EntityFolder.JUNK.equals(folderType) || + EntityFolder.USER.equals(folderType); + } private static File getFile(Context context) { return new File(context.getFilesDir(), "classifier.json");