From fb5c8101318436525da2ff3a38646d7d80351b0f Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 11 Dec 2021 07:55:23 +0100 Subject: [PATCH] Added message check rule conditions --- FAQ.md | 15 +++++- .../java/eu/faircode/email/EntityRule.java | 51 +++++++++++++------ 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/FAQ.md b/FAQ.md index 0626d4b8b2..dbd19bc3aa 100644 --- a/FAQ.md +++ b/FAQ.md @@ -2382,13 +2382,13 @@ Some common header conditions (regex): * *.*Auto-Submitted:.** [RFC3834](https://tools.ietf.org/html/rfc3834) * *.*Content-Type: multipart/report.** [RFC3462](https://tools.ietf.org/html/rfc3462) -You can match IMAP flags (keywords) via a header condition too (from version 1.1777), like this: +To match *set* IMAP flags (keywords) via a header condition (since version 1.1777): ``` $$ ``` -You can use these special values too, representing common system flags: +To match *set* message flags (since version 1.1777): ``` $$seen$ @@ -2397,6 +2397,17 @@ $$flagged$ $$deleted$ ``` +To match *passed* message checks (since version 1.1787): + +``` +$$dkim$ +$$spf$ +$$dmarc$ +$$mx$ +$$blocklist$ +$$replydomain$ +``` + Note that *regex* should be disable and that there should be no white space. The automation action will broadcast the intent *eu.faircode.email.AUTOMATION* with the following string extras: diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index 7a0575c772..605008c79b 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -265,21 +265,42 @@ public class EntityRule { value.endsWith("$")) { String keyword = value.substring(1, value.length() - 1); - List keywords = new ArrayList<>(); - if (message.ui_seen) - keywords.add("$seen"); - if (message.ui_answered) - keywords.add("$answered"); - if (message.ui_flagged) - keywords.add("$flagged"); - if (message.ui_deleted) - keywords.add("$deleted"); - if (message.infrastructure != null) - keywords.add('@' + message.infrastructure); - keywords.addAll(Arrays.asList(message.keywords)); - - if (!keywords.contains(keyword)) - return false; + if ("$dkim".equals(keyword)) { + if (!Boolean.TRUE.equals(message.dkim)) + return false; + } else if ("$spf".equals(keyword)) { + if (!Boolean.TRUE.equals(message.spf)) + return false; + } else if ("$dmarc".equals(keyword)) { + if (!Boolean.TRUE.equals(message.dmarc)) + return false; + } else if ("$mx".equals(keyword)) { + if (!Boolean.TRUE.equals(message.mx)) + return false; + } else if ("$blocklist".equals(keyword)) { + if (!Boolean.FALSE.equals(message.blocklist)) + return false; + } else if ("$replydomain".equals(keyword)) { + if (!Boolean.TRUE.equals(message.reply_domain)) + return false; + } else { + List keywords = new ArrayList<>(); + keywords.addAll(Arrays.asList(message.keywords)); + + if (message.ui_seen) + keywords.add("$seen"); + if (message.ui_answered) + keywords.add("$answered"); + if (message.ui_flagged) + keywords.add("$flagged"); + if (message.ui_deleted) + keywords.add("$deleted"); + if (message.infrastructure != null) + keywords.add('$' + message.infrastructure); + + if (!keywords.contains(keyword)) + return false; + } } else { if (headers == null) { if (message.headers == null)