From c2e48ea1f1993353619d7a641e4f68ca345d689d Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 16 Aug 2021 13:40:42 +0200 Subject: [PATCH] Added rules log type --- app/src/main/java/eu/faircode/email/Core.java | 11 +++--- .../java/eu/faircode/email/EntityLog.java | 2 +- .../eu/faircode/email/EntityOperation.java | 3 +- .../java/eu/faircode/email/EntityRule.java | 35 +++++++++++-------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 9aa8dacd28..57297727b9 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -3538,11 +3538,12 @@ class Core { if (message.blocklist != null && message.blocklist) { boolean use_blocklist = prefs.getBoolean("use_blocklist", false); if (use_blocklist) { - EntityLog.log(context, "Block list" + - " folder=" + folder.name + - " message=" + message.id + - "@" + new Date(message.received) + - ":" + message.subject); + EntityLog.log(context, EntityLog.Type.General, message, + "Block list" + + " folder=" + folder.name + + " message=" + message.id + + "@" + new Date(message.received) + + ":" + message.subject); EntityFolder junk = db.folder().getFolderByType(message.account, EntityFolder.JUNK); if (junk != null) { EntityOperation.queue(context, message, EntityOperation.MOVE, junk.id, false); diff --git a/app/src/main/java/eu/faircode/email/EntityLog.java b/app/src/main/java/eu/faircode/email/EntityLog.java index ffd1103461..9669a6bd95 100644 --- a/app/src/main/java/eu/faircode/email/EntityLog.java +++ b/app/src/main/java/eu/faircode/email/EntityLog.java @@ -62,7 +62,7 @@ public class EntityLog { @NonNull public String data; - enum Type {General, Statistics, Scheduling, Network, Account, Protocol, Classification, Notification} + enum Type {General, Statistics, Scheduling, Network, Account, Protocol, Classification, Notification, Rules} private static final ExecutorService executor = Helper.getBackgroundExecutor(1, "log"); diff --git a/app/src/main/java/eu/faircode/email/EntityOperation.java b/app/src/main/java/eu/faircode/email/EntityOperation.java index 574f8f969a..495a30e378 100644 --- a/app/src/main/java/eu/faircode/email/EntityOperation.java +++ b/app/src/main/java/eu/faircode/email/EntityOperation.java @@ -208,7 +208,8 @@ public class EntityOperation { jargs.put(1, autoread); jargs.put(3, autounflag); - EntityLog.log(context, "Move message=" + message.id + + EntityLog.log(context, EntityLog.Type.General,message, + "Move message=" + message.id + "@" + new Date(message.received) + ":" + message.subject + " source=" + source.id + ":" + source.type + ":" + source.name + "" + diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index 15f9c54bf4..aa71011854 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -19,6 +19,8 @@ package eu.faircode.email; Copyright 2018-2021 by Marcel Bokhorst (M66B) */ +import static androidx.room.ForeignKey.CASCADE; + import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -65,8 +67,6 @@ import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetHeaders; -import static androidx.room.ForeignKey.CASCADE; - @Entity( tableName = EntityRule.TABLE_NAME, foreignKeys = { @@ -164,7 +164,7 @@ public class EntityRule { } } else { String formatted = ((personal == null ? "" : personal + " ") + "<" + email + ">"); - if (matches(context, value, formatted, regex)) { + if (matches(context, message, value, formatted, regex)) { matches = true; break; } @@ -191,7 +191,7 @@ public class EntityRule { InternetAddress ia = (InternetAddress) recipient; String personal = ia.getPersonal(); String formatted = ((personal == null ? "" : personal + " ") + "<" + ia.getAddress() + ">"); - if (matches(context, value, formatted, regex)) { + if (matches(context, message, value, formatted, regex)) { matches = true; break; } @@ -206,7 +206,7 @@ public class EntityRule { String value = jsubject.getString("value"); boolean regex = jsubject.getBoolean("regex"); - if (!matches(context, value, message.subject, regex)) + if (!matches(context, message, value, message.subject, regex)) return false; } @@ -251,7 +251,7 @@ public class EntityRule { while (headers.hasMoreElements()) { Header header = headers.nextElement(); String formatted = header.getName() + ": " + header.getValue(); - if (matches(context, value, formatted, regex)) { + if (matches(context, message, value, formatted, regex)) { matches = true; break; } @@ -303,7 +303,7 @@ public class EntityRule { return true; } - private boolean matches(Context context, String needle, String haystack, boolean regex) { + private boolean matches(Context context, EntityMessage message, String needle, String haystack, boolean regex) { boolean matched = false; if (needle != null && haystack != null) if (regex) { @@ -313,8 +313,9 @@ public class EntityRule { matched = haystack.toLowerCase().contains(needle.trim().toLowerCase()); if (matched) - EntityLog.log(context, "Rule=" + name + ":" + order + " matched " + - " needle=" + needle + " haystack=" + haystack + " regex=" + regex); + EntityLog.log(context, EntityLog.Type.Rules, message, + "Rule=" + name + ":" + order + " matched " + + " needle=" + needle + " haystack=" + haystack + " regex=" + regex); else Log.i("Rule=" + name + ":" + order + " matched=" + matched + " needle=" + needle + " haystack=" + haystack + " regex=" + regex); @@ -504,7 +505,8 @@ public class EntityRule { boolean attachments = jargs.optBoolean("attachments"); if (message.auto_submitted != null && message.auto_submitted) { - EntityLog.log(context, "Auto submitted rule=" + name); + EntityLog.log(context, EntityLog.Type.Rules, message, + "Auto submitted rule=" + name); return false; } @@ -590,9 +592,10 @@ public class EntityRule { for (EntityMessage threaded : messages) if (!threaded.id.equals(message.id) && MessageHelper.equal(threaded.from, from)) { - EntityLog.log(context, "Answer loop" + - " name=" + answer.name + - " from=" + MessageHelper.formatAddresses(from)); + EntityLog.log(context, EntityLog.Type.Rules, message, + "Answer loop" + + " name=" + answer.name + + " from=" + MessageHelper.formatAddresses(from)); return; } @@ -695,7 +698,8 @@ public class EntityRule { automation.putExtra(EXTRA_RECEIVED, DTF.format(message.received)); List extras = Log.getExtras(automation.getExtras()); - EntityLog.log(context, "Sending " + automation + " " + TextUtils.join(" ", extras)); + EntityLog.log(context, EntityLog.Type.Rules, message, + "Sending " + automation + " " + TextUtils.join(" ", extras)); context.sendBroadcast(automation); return true; @@ -731,7 +735,8 @@ public class EntityRule { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); int callState = tm.getCallState(); if (callState != TelephonyManager.CALL_STATE_IDLE) { - EntityLog.log(context, "Call state=" + callState + " rule=" + rule.name); + EntityLog.log(context, EntityLog.Type.Rules, message, + "Call state=" + callState + " rule=" + rule.name); return; }