From 6019218e18f0ff280e02ecf8d369345d416a04a4 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 24 May 2024 08:33:57 +0200 Subject: [PATCH] Added auth results signer --- app/src/main/java/eu/faircode/email/Core.java | 18 +++++++++++---- .../java/eu/faircode/email/MessageHelper.java | 22 +++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index f4b5ea1bc4..11bc83375a 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -3505,12 +3505,12 @@ class Core { message.identity = (identity == null ? null : identity.id); boolean fromSelf = message.fromSelf(identity); + List signers = new ArrayList<>(); if (native_dkim && !fromSelf && !EntityFolder.isOutgoing(folder.type) && !BuildConfig.PLAY_STORE_RELEASE) { - List signers = helper.verifyDKIM(context); - message.signedby = (signers.isEmpty() ? null : TextUtils.join(",", signers)); + signers.addAll(helper.verifyDKIM(context)); message.dkim = !signers.isEmpty(); if (message.dkim) { boolean aligned = helper.isAligned(context, signers, message.return_path, message.smtp_from, message.from); @@ -3521,6 +3521,11 @@ class Core { } } + String signer = helper.getSigner(authentication); + if (signer != null) + signers.add(0, signer); + message.signedby = (signers.isEmpty() ? null : TextUtils.join(",", signers)); + if (message.size == null && message.total != null) message.size = message.total; @@ -4666,12 +4671,12 @@ class Core { message.identity = (identity == null ? null : identity.id); boolean fromSelf = message.fromSelf(identity); + List signers = new ArrayList<>(); if (native_dkim && !fromSelf && !EntityFolder.isOutgoing(folder.type) && !BuildConfig.PLAY_STORE_RELEASE) { - List signers = helper.verifyDKIM(context); - message.signedby = (signers.isEmpty() ? null : TextUtils.join(",", signers)); + signers.addAll(helper.verifyDKIM(context)); message.dkim = !signers.isEmpty(); if (message.dkim) { boolean aligned = helper.isAligned(context, signers, message.return_path, message.smtp_from, message.from); @@ -4682,6 +4687,11 @@ class Core { } } + String signer = helper.getSigner(authentication); + if (signer != null) + signers.add(0, signer); + message.signedby = (signers.isEmpty() ? null : TextUtils.join(",", signers)); + // Borrow reply name from sender name if (message.from != null && message.from.length == 1 && message.reply != null && message.reply.length == 1) { diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index da2b67f27a..08427c4a6e 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -2233,6 +2233,28 @@ public class MessageHelper { return mailfrom; } + String getSigner(String[] headers) { + if (headers == null || headers.length == 0) + return null; + + int semi = headers[0].indexOf(';'); + if (semi < 0) + return null; + String signer = headers[0].substring(0, semi).trim(); + + if (signer.toLowerCase(Locale.ROOT).startsWith("i=")) { + int semi2 = headers[0].indexOf(';', semi + 1); + if (semi2 < 0) + return null; + signer = headers[0].substring(semi + 1, semi2).trim(); + } + + if (TextUtils.isEmpty(signer)) + signer = null; + + return signer; + } + boolean getSPF() throws MessagingException { ensureHeaders();