From e1bb4034a47b319d654242ad812cf37b26ed93e6 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 19 Feb 2023 19:21:03 +0100 Subject: [PATCH] Added header condition DKIM alignment --- .../java/eu/faircode/email/EntityRule.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index 435630322f..d21fe0d781 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -301,6 +301,28 @@ public class EntityRule { if ("$tls".equals(keyword)) { if (!Boolean.TRUE.equals(message.tls)) return false; + } else if ("$aligned".equals(keyword)) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean native_dkim = prefs.getBoolean("native_dkim", false); + if (!native_dkim) + return false; + if (message.signedby == null) + return false; + if (message.from == null || message.from.length != 1) + return false; + String domain = UriHelper.getEmailDomain(((InternetAddress) message.from[0]).getAddress()); + if (domain == null) + return false; + boolean valid = false; + for (String signer : message.signedby.split(",")) + if (Objects.equals( + UriHelper.getRootDomain(context, signer), + UriHelper.getRootDomain(context, domain))) { + valid = true; + break; + } + if (!valid) + return false; } else if ("$dkim".equals(keyword)) { if (!Boolean.TRUE.equals(message.dkim)) return false;