Refactoring

pull/190/head
M66B 4 years ago
parent d35f04d668
commit d0879f012f

@ -999,8 +999,9 @@ class Core {
throw new IllegalArgumentException("self"); throw new IllegalArgumentException("self");
// De-classify // De-classify
for (EntityMessage message : messages) if (MessageClassifier.canClassify(folder.type))
MessageClassifier.classify(message, target, context); for (EntityMessage message : messages)
MessageClassifier.classify(message, false, context);
IMAPFolder itarget = (IMAPFolder) istore.getFolder(target.name); IMAPFolder itarget = (IMAPFolder) istore.getFolder(target.name);
@ -1503,7 +1504,7 @@ class Core {
parts.isPlainOnly(), parts.isPlainOnly(),
HtmlHelper.getPreview(body), HtmlHelper.getPreview(body),
parts.getWarnings(message.warning)); parts.getWarnings(message.warning));
MessageClassifier.classify(message, null, context); MessageClassifier.classify(message, true, context);
if (body != null) if (body != null)
EntityLog.log(context, "Operation body size=" + body.length()); EntityLog.log(context, "Operation body size=" + body.length());
@ -3010,7 +3011,7 @@ class Core {
parts.isPlainOnly(), parts.isPlainOnly(),
HtmlHelper.getPreview(body), HtmlHelper.getPreview(body),
parts.getWarnings(message.warning)); parts.getWarnings(message.warning));
MessageClassifier.classify(message, null, context); MessageClassifier.classify(message, true, context);
if (!message.ui_hide) if (!message.ui_hide)
db.message().setMessageUiHide(message.id, false); db.message().setMessageUiHide(message.id, false);
@ -3445,7 +3446,7 @@ class Core {
parts.isPlainOnly(), parts.isPlainOnly(),
HtmlHelper.getPreview(body), HtmlHelper.getPreview(body),
parts.getWarnings(message.warning)); parts.getWarnings(message.warning));
MessageClassifier.classify(message, null, context); MessageClassifier.classify(message, true, context);
if (stats != null && body != null) if (stats != null && body != null)
stats.content += body.length(); stats.content += body.length();

@ -51,14 +51,11 @@ public class MessageClassifier {
private static final double COMMON_WORD_FACTOR = 0.75; private static final double COMMON_WORD_FACTOR = 0.75;
private static final double CHANCE_THRESHOLD = 2.0; 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 { try {
if (!isEnabled(context)) if (!isEnabled(context))
return; return;
if (target != null && !canClassify(target.type))
return;
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityFolder folder = db.folder().getFolder(message.folder); EntityFolder folder = db.folder().getFolder(message.folder);
@ -87,7 +84,7 @@ public class MessageClassifier {
if (!wordClassFrequency.containsKey(account.id)) if (!wordClassFrequency.containsKey(account.id))
wordClassFrequency.put(account.id, new HashMap<>()); 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" + EntityLog.log(context, "Classifier" +
" folder=" + folder.name + " folder=" + folder.name +
@ -98,7 +95,7 @@ public class MessageClassifier {
" re=" + message.auto_classified); " re=" + message.auto_classified);
Integer m = classMessages.get(account.id).get(folder.name); Integer m = classMessages.get(account.id).get(folder.name);
if (target == null) { if (added) {
m = (m == null ? 1 : m + 1); m = (m == null ? 1 : m + 1);
classMessages.get(account.id).put(folder.name, m); classMessages.get(account.id).put(folder.name, m);
} else { } else {
@ -113,11 +110,11 @@ public class MessageClassifier {
try { try {
db.beginTransaction(); db.beginTransaction();
EntityFolder f = db.folder().getFolderByName(account.id, classified); EntityFolder target = db.folder().getFolderByName(account.id, classified);
if (f != null && !f.id.equals(folder.id) && f.auto_classify && if (target != null && !target.id.equals(folder.id) && target.auto_classify &&
(EntityFolder.JUNK.equals(f.type) || ActivityBilling.isPro(context))) { (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; message.ui_hide = true;
} }

Loading…
Cancel
Save