Decode first received SPF header

pull/201/head
M66B 4 years ago
parent 6a3de2621d
commit c49543cc0a

@ -2469,6 +2469,8 @@ class Core {
message.bimi_selector = helper.getBimiSelector(); message.bimi_selector = helper.getBimiSelector();
message.dkim = MessageHelper.getAuthentication("dkim", authentication); message.dkim = MessageHelper.getAuthentication("dkim", authentication);
message.spf = MessageHelper.getAuthentication("spf", authentication); message.spf = MessageHelper.getAuthentication("spf", authentication);
if (message.spf == null && helper.getSPF())
message.spf = true;
message.dmarc = MessageHelper.getAuthentication("dmarc", authentication); message.dmarc = MessageHelper.getAuthentication("dmarc", authentication);
message.return_path = helper.getReturnPath(); message.return_path = helper.getReturnPath();
message.submitter = helper.getSender(); message.submitter = helper.getSender();
@ -3347,6 +3349,8 @@ class Core {
message.bimi_selector = helper.getBimiSelector(); message.bimi_selector = helper.getBimiSelector();
message.dkim = MessageHelper.getAuthentication("dkim", authentication); message.dkim = MessageHelper.getAuthentication("dkim", authentication);
message.spf = MessageHelper.getAuthentication("spf", authentication); message.spf = MessageHelper.getAuthentication("spf", authentication);
if (message.spf == null && helper.getSPF())
message.spf = true;
message.dmarc = MessageHelper.getAuthentication("dmarc", authentication); message.dmarc = MessageHelper.getAuthentication("dmarc", authentication);
message.return_path = helper.getReturnPath(); message.return_path = helper.getReturnPath();
message.submitter = helper.getSender(); message.submitter = helper.getSender();

@ -1293,6 +1293,18 @@ public class MessageHelper {
return result; return result;
} }
boolean getSPF() throws MessagingException {
ensureHeaders();
// http://www.open-spf.org/RFC_4408/#header-field
String[] headers = imessage.getHeader("Received-SPF");
if (headers == null || headers.length < 1)
return false;
String spf = MimeUtility.unfold(headers[0]);
return (spf.trim().toLowerCase(Locale.ROOT).startsWith("pass"));
}
private String fixEncoding(String name, String header) { private String fixEncoding(String name, String header) {
if (header.trim().startsWith("=?")) if (header.trim().startsWith("=?"))
return header; return header;

Loading…
Cancel
Save