mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
d35f04d668
commit
d0879f012f
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue