Comparing version 1.0.13 to 1.0.14
@@ -8,2 +8,3 @@ 'use strict'; | ||
const { bimi } = require('./bimi'); | ||
const { parseReceived } = require('./parse-received'); | ||
const libmime = require('libmime'); | ||
@@ -17,5 +18,6 @@ const os = require('os'); | ||
* @param {Object} opts Message options | ||
* @param {String} opts.sender Address from MAIL FROM | ||
* @param {String} opts.ip Client IP address | ||
* @param {String} opts.helo Hostname from EHLO/HELO | ||
* @param {Boolean} [opts.trustReceived] If true then parses ip and helo values from Received header | ||
* @param {String} [opts.sender] Address from MAIL FROM. Parsed from Return-Path if not set | ||
* @param {String} [opts.ip] Client IP address | ||
* @param {String} [opts.helo] Hostname from EHLO/HELO | ||
* @param {String} [opts.mta] MTA/MX hostname (defaults to os.hostname) | ||
@@ -32,13 +34,43 @@ * @param {Object} [opts.seal] ARC sealing options | ||
const authenticate = async (input, opts) => { | ||
opts = Object.assign({}, opts); // copy keys | ||
opts.mta = opts.mta || os.hostname(); | ||
const [dkimResult, spfResult] = await Promise.all([ | ||
dkimVerify(input, { | ||
resolver: opts.resolver, | ||
sender: opts.sender, | ||
seal: opts.seal | ||
}), | ||
spf(opts) | ||
]); | ||
const dkimResult = await dkimVerify(input, { | ||
resolver: opts.resolver, | ||
sender: opts.sender, // defaults to Return-Path header | ||
seal: opts.seal | ||
}); | ||
const receivedChain = dkimResult.headers?.parsed.filter(r => r.key === 'received').map(row => parseReceived(row.line)); | ||
// parse client information from last Received header if needed | ||
if (opts.trustReceived) { | ||
if (dkimResult.envelopeFrom && !opts.sender) { | ||
opts.sender = dkimResult.envelopeFrom; | ||
} | ||
let rcvd = receivedChain?.[0]; | ||
if (rcvd?.from) { | ||
let helo = rcvd.from.value; | ||
let ip; | ||
if (rcvd.from.comment) { | ||
let ipMatch = rcvd.from.comment.match(/\[([^\]]+)\]/); | ||
if (ipMatch) { | ||
ip = ipMatch[1].replace(/^IPv6:/i, ''); | ||
} | ||
} | ||
if (ip && !opts.ip) { | ||
opts.ip = ip; | ||
} | ||
if (helo && !opts.helo) { | ||
opts.helo = helo; | ||
} | ||
} | ||
} | ||
const spfResult = await spf(opts); | ||
let arcResult; | ||
@@ -124,2 +156,3 @@ if (!opts.disableArc) { | ||
return { | ||
receivedChain, | ||
dkim: dkimResult, | ||
@@ -126,0 +159,0 @@ spf: spfResult, |
{ | ||
"name": "mailauth", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"description": "Email authentication library for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/mailauth.js", |
@@ -26,12 +26,16 @@ ![](https://github.com/andris9/mailauth/raw/master/assets/mailauth.png) | ||
const { authenticate } = require('mailauth'); | ||
const { dkim, spf, arc, dmarc, bimi, headers } = await authenticate( | ||
const { dkim, spf, arc, dmarc, bimi, receivedChain, headers } = await authenticate( | ||
message, // either a String, a Buffer or a Readable Stream | ||
{ | ||
// SMTP transmission options must be provided as | ||
// these are not parsed from the message | ||
// SMTP transmission options if available | ||
ip: '217.146.67.33', // SMTP client IP | ||
helo: 'uvn-67-33.tll01.zonevs.eu', // EHLO/HELO hostname | ||
mta: 'mx.ethereal.email', // server processing this message, defaults to os.hostname() | ||
sender: 'andris@ekiri.ee', // MAIL FROM address | ||
// If you do not want to provide ip/helo/sender manually but parse from the message | ||
//trustReceived: true, | ||
// Server processing this message, defaults to os.hostname(). Inserted into Authentication headers | ||
mta: 'mx.ethereal.email', | ||
// Optional DNS resolver function (defaults to `dns.promises.resolve`) | ||
@@ -61,2 +65,6 @@ resolver: async (name, rr) => await dns.promises.resolve(name, rr) | ||
### receivedChain | ||
`receivedChain` property is an array of parsed representations of the `Received:` headers | ||
## DKIM | ||
@@ -339,3 +347,3 @@ | ||
``` | ||
getPolicy(domain [,knownPolicy]) -> {policy, status} | ||
async getPolicy(domain [,knownPolicy]) -> {policy, status} | ||
``` | ||
@@ -342,0 +350,0 @@ |
225989
30
3623
455