1
0
mirror of https://github.com/MailHops/mailhops-plugin.git synced 2025-05-16 06:10:08 -07:00

Merge pull request #36 from Ionic/feature/rework-received-spf

Rework Received-SPF header parsing.
This commit is contained in:
Andrew Van Tassel 2024-07-24 16:24:09 -06:00 committed by GitHub
commit 07410ef5b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -299,17 +299,44 @@ class MailHops {
browser.messageDisplayAction.setTitle({ title: this.message.sender.title, tabId: this.tabId });
}
sanitizeString(str) {
return str.replace (/\t/g, ' ').replace (/\s+/g, ' ').replace (/</g, '&lt;').replace (/>/g, '&gt;').trim ();
}
auth(header_xmailer, header_useragent, header_xmimeole, header_auth, header_spf, header_unsubscribe) {
let auth = [];
//SPF
if (header_spf) {
header_spf = header_spf.replace(/^\s+/, "");
// Compact whitespace, make sure addresses enclosed in <> parse as valid
// XHTMl later on.
header_spf = this.sanitizeString (header_spf);
// Split value on whitespace. We'll extract data from this.
var headerSPFArr = header_spf.split(' ');
// First element should always indicate the state.
var spfState = headerSPFArr.shift ();
// Additionally, we might have a reason description, enclosed in parenthesis.
// Example: spfState = "Pass", reason description: "(mailfrom)"
var spfStateReason = '';
if (-1 != headerSPFArr[0].search (/^\(.*\)$/)) {
spfStateReason = ' ' + headerSPFArr.shift ();
}
// Put it all together, with extra information if requested.
var copy = spfState + spfStateReason;
if (this.options.extrainfo) {
copy += '\n<br />' + headerSPFArr.join (' ') + '\n<br />';
}
copy += '\n<br />' + MailHopsUtils.spf(spfState.toLowerCase ()).trim ();
this.LOG ("SPF state and data: " + copy);
auth.push({
type: 'SPF',
color: 'green',
icon: '/images/auth/' + headerSPFArr[0] + '.png',
copy: header_spf + '\n' + MailHopsUtils.spf(headerSPFArr[0]).trim()
icon: '/images/auth/' + spfState.toLowerCase () + '.png',
copy: copy
});
}
//Authentication-Results