Check for native DKIM alignment

This commit is contained in:
M66B 2024-05-21 08:38:20 +02:00
parent c7aa1b8297
commit 9e131fb359
2 changed files with 26 additions and 32 deletions

View File

@ -3504,22 +3504,10 @@ class Core {
if (native_dkim && !BuildConfig.PLAY_STORE_RELEASE) {
List<String> signers = helper.verifyDKIM(context);
message.signedby = (signers.size() == 0 ? null : TextUtils.join(",", signers));
if (Boolean.TRUE.equals(message.dkim)) {
if (signers.size() == 0)
message.dkim = false;
} else {
if (message.from != null)
for (Address from : message.from) {
String domain = UriHelper.getEmailDomain(((InternetAddress) from).getAddress());
if (domain != null && signers.contains(domain)) {
message.dkim = true;
break;
}
}
}
if (!Boolean.TRUE.equals(message.dkim))
message.dmarc = message.dkim;
message.signedby = (signers.isEmpty() ? null : TextUtils.join(",", signers));
message.dkim = !signers.isEmpty();
message.dmarc = Boolean.TRUE.equals(message.dmarc) ||
helper.isAligned(context, signers, message.return_path, message.from);
}
if (message.size == null && message.total != null)
@ -4668,22 +4656,10 @@ class Core {
if (native_dkim && !BuildConfig.PLAY_STORE_RELEASE) {
List<String> signers = helper.verifyDKIM(context);
message.signedby = (signers.size() == 0 ? null : TextUtils.join(",", signers));
if (Boolean.TRUE.equals(message.dkim)) {
if (signers.size() == 0)
message.dkim = false;
} else {
if (message.from != null)
for (Address from : message.from) {
String domain = UriHelper.getEmailDomain(((InternetAddress) from).getAddress());
if (domain != null && signers.contains(domain)) {
message.dkim = true;
break;
}
}
}
if (!Boolean.TRUE.equals(message.dkim))
message.dmarc = message.dkim;
message.signedby = (signers.isEmpty() ? null : TextUtils.join(",", signers));
message.dkim = !signers.isEmpty();
message.dmarc = Boolean.TRUE.equals(message.dmarc) ||
helper.isAligned(context, signers, message.return_path, message.from);
}
// Borrow reply name from sender name

View File

@ -2610,6 +2610,24 @@ public class MessageHelper {
return null;
}
boolean isAligned(Context context, List<String> signers, Address[] return_path, Address[] from) {
List<Address> envelop = new ArrayList<>();
if (return_path != null)
envelop.addAll(Arrays.asList(return_path));
if (from != null)
envelop.addAll(Arrays.asList(from));
for (String signer : signers) {
for (Address a : envelop) {
String domain = UriHelper.getEmailDomain(((InternetAddress) a).getAddress());
if (domain != null && Objects.equals(
UriHelper.getRootDomain(context, signer),
UriHelper.getRootDomain(context, domain)))
return true;
}
}
return false;
}
Address[] getMailFrom(String[] headers) {
if (headers == null)
return null;