Auto delete block sender rules

pull/178/head
M66B 5 years ago
parent d5a2b0fe4a
commit 76a0ff9ba8

@ -188,7 +188,6 @@ public class EntityOperation {
db.message().setMessageImportance(similar.id, null);
}
EntityAccount account = db.account().getAccount(message.account);
if (!"imap.gmail.com".equalsIgnoreCase(account == null ? null : account.host) ||
!EntityFolder.ARCHIVE.equals(source.type) ||
@ -201,6 +200,13 @@ public class EntityOperation {
EntityMessage.snooze(context, message.id, null);
}
if (EntityFolder.JUNK.equals(source.type) && EntityFolder.INBOX.equals(target.type)) {
List<EntityRule> rules = db.rule().getRules(target.id);
for (EntityRule rule : rules)
if (rule.isBlockingSender(message, source))
db.rule().deleteRule(rule.id);
}
// Create copy without uid in target folder
// Message with same msgid can be in archive
if (message.uid != null &&

@ -567,7 +567,7 @@ public class EntityRule {
jcondition.put("sender", jsender);
JSONObject jaction = new JSONObject();
jaction.put("type", EntityRule.TYPE_MOVE);
jaction.put("type", TYPE_MOVE);
jaction.put("target", junk.id);
DB db = DB.getInstance(context);
@ -584,6 +584,34 @@ public class EntityRule {
return rule;
}
boolean isBlockingSender(EntityMessage message, EntityFolder junk) throws JSONException {
if (message.from == null || message.from.length == 0)
return false;
String sender = ((InternetAddress) message.from[0]).getAddress();
if (sender == null)
return false;
int at = sender.indexOf('@');
String domain = (at < 0 ? sender : sender.substring(at));
JSONObject jcondition = new JSONObject(condition);
if (!jcondition.has("sender"))
return false;
JSONObject jsender = jcondition.getJSONObject("sender");
if (jsender.optBoolean("regex"))
return false;
String value = jsender.optString("value");
if (!sender.equals(value) && !domain.equals(value))
return false;
JSONObject jaction = new JSONObject(action);
if (jaction.optInt("type", -1) != TYPE_MOVE)
return false;
if (jaction.optInt("target", -1) != junk.id)
return false;
return true;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof EntityRule) {

Loading…
Cancel
Save