Comparing version 4.6.9 to 4.7.0
# Changelog | ||
## [4.7.0](https://github.com/postalsys/mailauth/compare/v4.6.9...v4.7.0) (2024-10-02) | ||
### Features | ||
* **dkim-sign:** Added new Transfor stream class DkimSignStream to sign emails in a stream processing pipeline ([130a1a3](https://github.com/postalsys/mailauth/commit/130a1a3812fac2ad710f244510ca60887c2d33a9)) | ||
## [4.6.9](https://github.com/postalsys/mailauth/compare/v4.6.8...v4.6.9) (2024-08-22) | ||
@@ -4,0 +11,0 @@ |
@@ -5,2 +5,3 @@ 'use strict'; | ||
const { DkimSigner } = require('./dkim-signer'); | ||
const { Transform } = require('node:stream'); | ||
@@ -14,2 +15,65 @@ const dkimSign = async (input, options) => { | ||
module.exports = { dkimSign }; | ||
class DkimSignStream extends Transform { | ||
constructor(options) { | ||
super(options); | ||
this.signer = new DkimSigner(options); | ||
this.chunks = []; | ||
this.chunklen = 0; | ||
this.errors = null; | ||
this.finished = false; | ||
this.finishCb = null; | ||
this.signer.on('end', () => this.finishStream()); | ||
this.signer.on('finish', () => this.finishStream()); | ||
this.signer.on('error', err => { | ||
this.finished = true; | ||
this.destroy(err); | ||
}); | ||
} | ||
finishStream() { | ||
if (this.finished || !this.finishCb) { | ||
return; | ||
} | ||
this.finished = true; | ||
let done = this.finishCb; | ||
this.finishCb = null; | ||
this.errors = this.signer.errors; | ||
this.push(Buffer.from(this.signer.signatureHeaders.join('\r\n') + '\r\n')); | ||
this.push(Buffer.concat(this.chunks, this.chunklen)); | ||
done(); | ||
} | ||
_transform(chunk, encoding, done) { | ||
if (!chunk || !chunk.length || this.finished) { | ||
return done(); | ||
} | ||
if (typeof chunk === 'string') { | ||
chunk = Buffer.from(chunk, encoding); | ||
} | ||
this.chunks.push(chunk); | ||
this.chunklen += chunk.length; | ||
if (this.signer.write(chunk) === false) { | ||
// wait for drain | ||
return this.signer.once('drain', done); | ||
} | ||
done(); | ||
} | ||
_flush(done) { | ||
if (this.finished) { | ||
return done(); | ||
} | ||
this.finishCb = done; | ||
this.signer.end(); | ||
} | ||
} | ||
module.exports = { dkimSign, DkimSignStream }; |
@@ -44,5 +44,5 @@ 'use strict'; | ||
_transform(chunk, encodng, done) { | ||
_transform(chunk, encoding, done) { | ||
if (typeof chunk === 'string') { | ||
chunk = Buffer.from(chunk, encodng); | ||
chunk = Buffer.from(chunk, encoding); | ||
} | ||
@@ -49,0 +49,0 @@ |
{ | ||
"name": "mailauth", | ||
"version": "4.6.9", | ||
"version": "4.7.0", | ||
"description": "Email authentication library for Node.js", | ||
@@ -41,3 +41,3 @@ "main": "lib/mailauth.js", | ||
"js-yaml": "4.1.0", | ||
"license-report": "6.5.0", | ||
"license-report": "6.7.0", | ||
"marked": "0.7.0", | ||
@@ -50,9 +50,9 @@ "marked-man": "0.7.0", | ||
"@postalsys/vmc": "1.0.8", | ||
"fast-xml-parser": "4.4.1", | ||
"fast-xml-parser": "4.5.0", | ||
"ipaddr.js": "2.2.0", | ||
"joi": "17.13.3", | ||
"libmime": "5.3.5", | ||
"nodemailer": "6.9.14", | ||
"nodemailer": "6.9.15", | ||
"punycode.js": "2.3.1", | ||
"tldts": "6.1.40", | ||
"tldts": "6.1.49", | ||
"undici": "5.28.4", | ||
@@ -59,0 +59,0 @@ "yargs": "17.7.2" |
@@ -160,2 +160,48 @@ ![](https://github.com/postalsys/mailauth/raw/master/assets/mailauth.png) | ||
### Signing as a PassThrough Stream | ||
Use `DkimSignStream` stream if you want to use DKIM signing as part of a stream processing pipeline. | ||
```js | ||
const { DkimSignStream } = require('mailauth/lib/dkim/sign'); | ||
const dkimSignStream = new DkimSignStream({ | ||
// Optional, default canonicalization, default is "relaxed/relaxed" | ||
canonicalization: 'relaxed/relaxed', // c= | ||
// Optional, default signing and hashing algorithm | ||
// Mostly useful when you want to use rsa-sha1, otherwise no need to set | ||
algorithm: 'rsa-sha256', | ||
// Optional, default is current time | ||
signTime: new Date(), // t= | ||
// Keys for one or more signatures | ||
// Different signatures can use different algorithms (mostly useful when | ||
// you want to sign a message both with RSA and Ed25519) | ||
signatureData: [ | ||
{ | ||
signingDomain: 'tahvel.info', // d= | ||
selector: 'test.rsa', // s= | ||
// supported key types: RSA, Ed25519 | ||
privateKey: fs.readFileSync('./test/fixtures/private-rsa.pem'), | ||
// Optional algorithm, default is derived from the key. | ||
// Overrides whatever was set in parent object | ||
algorithm: 'rsa-sha256', | ||
// Optional signature specifc canonicalization, overrides whatever was set in parent object | ||
canonicalization: 'relaxed/relaxed' // c= | ||
// Maximum number of canonicalized body bytes to sign (eg. the "l=" tag). | ||
// Do not use though. This is available only for compatibility testing. | ||
// maxBodyLength: 12345 | ||
} | ||
] | ||
}); | ||
// Writes a signed message to the output | ||
process.stdin.pipe(dkimSignStream).pipe(process.stdout); | ||
``` | ||
### Verifying | ||
@@ -162,0 +208,0 @@ |
Sorry, the diff of this file is not supported yet
288642
5585
522
+ Addedfast-xml-parser@4.5.0(transitive)
+ Addednodemailer@6.9.15(transitive)
+ Addedtldts@6.1.49(transitive)
- Removedfast-xml-parser@4.4.1(transitive)
- Removednodemailer@6.9.14(transitive)
- Removedtldts@6.1.40(transitive)
Updatedfast-xml-parser@4.5.0
Updatednodemailer@6.9.15
Updatedtldts@6.1.49