mirror of https://github.com/M66B/FairEmail.git
Check DKIM requirements
This commit is contained in:
parent
4dbed4a887
commit
f286ca533a
|
@ -2953,6 +2953,8 @@ class Core {
|
|||
message.bimi_selector = helper.getBimiSelector();
|
||||
message.tls = helper.getTLS();
|
||||
message.dkim = MessageHelper.getAuthentication("dkim", authentication);
|
||||
if (Boolean.TRUE.equals(message.dkim))
|
||||
message.dkim = helper.checkDKIMRequirements();
|
||||
message.spf = MessageHelper.getAuthentication("spf", authentication);
|
||||
if (message.spf == null && helper.getSPF())
|
||||
message.spf = true;
|
||||
|
@ -3921,6 +3923,8 @@ class Core {
|
|||
message.bimi_selector = helper.getBimiSelector();
|
||||
message.tls = helper.getTLS();
|
||||
message.dkim = MessageHelper.getAuthentication("dkim", authentication);
|
||||
if (Boolean.TRUE.equals(message.dkim))
|
||||
message.dkim = helper.checkDKIMRequirements();
|
||||
message.spf = MessageHelper.getAuthentication("spf", authentication);
|
||||
if (message.spf == null && helper.getSPF())
|
||||
message.spf = true;
|
||||
|
|
|
@ -1832,6 +1832,39 @@ public class MessageHelper {
|
|||
return (spf.trim().toLowerCase(Locale.ROOT).startsWith("pass"));
|
||||
}
|
||||
|
||||
boolean checkDKIMRequirements() throws MessagingException {
|
||||
ensureHeaders();
|
||||
|
||||
String[] headers = imessage.getHeader("DKIM-Signature");
|
||||
if (headers == null || headers.length < 1)
|
||||
return false;
|
||||
|
||||
for (String header : headers) {
|
||||
Map<String, String> kv = getKeyValues(header);
|
||||
|
||||
// Hashed body length
|
||||
Integer l = Helper.parseInt(kv.get("l"));
|
||||
if (l != null && l == 0) {
|
||||
Log.w("DKIM body length=" + l);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Hashed header fields
|
||||
String h = kv.get("h");
|
||||
if (h == null) {
|
||||
Log.w("DKIM header fields missing");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Arrays.asList(h.split(":")).contains("from")) {
|
||||
Log.i("DKIM headers fields missing 'from'");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Address[] getMailFrom(String[] headers) {
|
||||
if (headers == null)
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue