authheaders
Advanced tools
Comparing version 0.0.2 to 1.0.0
50
index.js
@@ -40,2 +40,4 @@ const path = require('path'); | ||
const KEYS = ['spf', 'dkim', 'arc', 'dmarc']; | ||
function authenticateMessage(message, ...args) { | ||
@@ -61,3 +63,49 @@ const command = `python3 ${scripts.authenticateMessage} ${args.join(' ')}`; | ||
if (stderr.length > 0) return reject(new Error(stderr.join(''))); | ||
resolve(stdout.join('')); | ||
// Authentication-Results: mx1.forwardemail.net; spf=fail reason="SPF fail - not authorized" smtp.helo=jacks-macbook-pro.local smtp.mailfrom=foo@forwardemail.net; dkim=fail; arc=none; dmarc=fail (Used From Domain Record) header.from=forwardemail.net policy.dmarc=reject | ||
const result = { header: stdout.join('').trim() }; | ||
for (const key of KEYS) { | ||
result[key] = {}; | ||
} | ||
result.dmarc.policy = 'none'; | ||
const terms = result.header | ||
.split(/;/) | ||
.map((t) => t.trim()) | ||
.filter((t) => t !== ''); | ||
for (const term of terms) { | ||
const split = term.split('='); | ||
if (term.startsWith('spf=')) { | ||
result.spf.result = split[1].split(' ')[0]; | ||
const index = term.indexOf('reason='); | ||
if (index !== -1) | ||
result.spf.reason = term | ||
.slice(index + 'reason='.length) | ||
.split('"')[1]; | ||
} else if (term.startsWith('dkim=')) { | ||
result.dkim.result = split[1].split(' ')[0]; | ||
const index = term.indexOf('('); | ||
if (index !== -1) | ||
result.dkim.reason = term.slice(index + '('.length).split(')')[0]; | ||
} else if (term.startsWith('arc=')) { | ||
result.arc.result = split[1].split(' ')[0]; | ||
// TODO: right now this does not return a comment due to this issue: | ||
// <https://github.com/ValiMail/authentication-headers/issues/12 | ||
} else if (term.startsWith('dmarc=')) { | ||
result.dmarc.result = split[1].split(' ')[0]; | ||
// reason | ||
const index = term.indexOf('('); | ||
if (index !== -1) | ||
result.dmarc.reason = term.slice(index + '('.length).split(')')[0]; | ||
// policy | ||
const policyIndex = term.indexOf('policy.dmarc='); | ||
if (policyIndex !== -1) | ||
result.dmarc.policy = term | ||
.slice(policyIndex + 'policy.dmarc='.length) | ||
.split(' ')[0]; | ||
} | ||
} | ||
resolve(result); | ||
}); | ||
@@ -64,0 +112,0 @@ }); |
{ | ||
"name": "authheaders", | ||
"description": "Node.js wrapper around the Python pip package authheaders", | ||
"version": "0.0.2", | ||
"version": "1.0.0", | ||
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -97,5 +97,17 @@ # authheaders | ||
The value of `result` is an String with the new Authentication-Results header to add to the top of the message headers. | ||
The value of `result` is an Object with properties `header` (String), and Objects for `spf`, `dkim`, `arc`, and `dmarc`. These Object's contain a `result` (String) and conditionally a `reason` (String) value. | ||
An example `result` object is provided below: | ||
```js | ||
{ | ||
header: 'Authentication-Results: example.com; spf=none smtp.helo=domain.of.sender.net smtp.mailfrom=test.com; dkim=pass header.d=forwardemail.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=gmail.com policy.dmarc=none', | ||
spf: { result: 'none' }, | ||
dkim: { result: 'pass' }, | ||
arc: { result: 'pass' }, | ||
dmarc: { policy: 'none', result: 'fail', reason: 'Used From Domain Record' } | ||
} | ||
``` | ||
## Contributors | ||
@@ -102,0 +114,0 @@ |
@@ -32,6 +32,20 @@ const fs = require('fs'); | ||
t.is( | ||
result, | ||
'Authentication-Results: example.com; spf=none smtp.helo=domain.of.sender.net smtp.mailfrom=test.com; dkim=pass header.d=forwardemail.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=gmail.com policy.dmarc=none' | ||
); | ||
t.deepEqual(result, { | ||
arc: { | ||
result: 'pass' | ||
}, | ||
dkim: { | ||
result: 'pass' | ||
}, | ||
dmarc: { | ||
policy: 'none', | ||
reason: 'Used From Domain Record', | ||
result: 'fail' | ||
}, | ||
header: | ||
'Authentication-Results: example.com; spf=none smtp.helo=domain.of.sender.net smtp.mailfrom=test.com; dkim=pass header.d=forwardemail.net; arc=pass; dmarc=fail (Used From Domain Record) header.from=gmail.com policy.dmarc=none', | ||
spf: { | ||
result: 'none' | ||
} | ||
}); | ||
}); | ||
@@ -50,3 +64,2 @@ | ||
); | ||
t.pass(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
25072
167
0
131