mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-01 09:16:00 +00:00
Evuluate Received-SPF
This commit is contained in:
parent
7f4c0f6efb
commit
ade60c608b
3 changed files with 25 additions and 9 deletions
|
@ -3454,8 +3454,8 @@ class Core {
|
|||
message.tls = helper.getTLS();
|
||||
message.dkim = MessageHelper.getAuthentication("dkim", authentication);
|
||||
message.spf = MessageHelper.getAuthentication("spf", authentication);
|
||||
if (message.spf == null && helper.getSPF())
|
||||
message.spf = true;
|
||||
if (message.spf == null)
|
||||
message.spf = helper.getSPF();
|
||||
message.dmarc = MessageHelper.getAuthentication("dmarc", authentication);
|
||||
message.auth = MessageHelper.getAuthentication("auth", authentication);
|
||||
message.smtp_from = helper.getMailFrom(authentication);
|
||||
|
@ -4634,8 +4634,8 @@ class Core {
|
|||
message.tls = helper.getTLS();
|
||||
message.dkim = MessageHelper.getAuthentication("dkim", authentication);
|
||||
message.spf = MessageHelper.getAuthentication("spf", authentication);
|
||||
if (message.spf == null && helper.getSPF())
|
||||
message.spf = true;
|
||||
if (message.spf == null)
|
||||
message.spf = helper.getSPF();
|
||||
message.dmarc = MessageHelper.getAuthentication("dmarc", authentication);
|
||||
message.auth = MessageHelper.getAuthentication("auth", authentication);
|
||||
message.smtp_from = helper.getMailFrom(authentication);
|
||||
|
|
|
@ -1557,8 +1557,8 @@ public class FragmentFolders extends FragmentBase {
|
|||
message.tls = helper.getTLS();
|
||||
message.dkim = MessageHelper.getAuthentication("dkim", authentication);
|
||||
message.spf = MessageHelper.getAuthentication("spf", authentication);
|
||||
if (message.spf == null && helper.getSPF())
|
||||
message.spf = true;
|
||||
if (message.spf == null)
|
||||
message.spf = helper.getSPF();
|
||||
message.dmarc = MessageHelper.getAuthentication("dmarc", authentication);
|
||||
message.auth = MessageHelper.getAuthentication("auth", authentication);
|
||||
message.smtp_from = helper.getMailFrom(authentication);
|
||||
|
|
|
@ -2272,16 +2272,32 @@ public class MessageHelper {
|
|||
return signer;
|
||||
}
|
||||
|
||||
boolean getSPF() throws MessagingException {
|
||||
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;
|
||||
return null;
|
||||
|
||||
// header-field = "Received-SPF:" [CFWS] result FWS [comment FWS] [ key-value-list ] CRLF
|
||||
// result = "Pass" / "Fail" / "SoftFail" / "Neutral" / "None" / "TempError" / "PermError"
|
||||
|
||||
String spf = MimeUtility.unfold(headers[0]);
|
||||
return (spf.trim().toLowerCase(Locale.ROOT).startsWith("pass"));
|
||||
String[] values = spf.trim().split("\\s+");
|
||||
if (values.length == 0)
|
||||
return null;
|
||||
|
||||
String value = values[0].toLowerCase(Locale.ROOT);
|
||||
switch (value) {
|
||||
case "pass":
|
||||
return true;
|
||||
case "neutral":
|
||||
case "none":
|
||||
return null;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
Loading…
Reference in a new issue