mailauth 4.7.0 → 4.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.7.1](https://github.com/postalsys/mailauth/compare/v4.7.0...v4.7.1) (2024-10-02)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **dkim:** New class BodyHashStream ([88d2fad](https://github.com/postalsys/mailauth/commit/88d2fad329a9a6fc8ebc1da4efc1c4844ae49507))
9
+
3
10
  ## [4.7.0](https://github.com/postalsys/mailauth/compare/v4.6.9...v4.7.0) (2024-10-02)
4
11
 
5
12
 
@@ -1,7 +1,9 @@
1
1
  'use strict';
2
2
 
3
- let { SimpleHash } = require('./simple');
4
- let { RelaxedHash } = require('./relaxed');
3
+ const { SimpleHash } = require('./simple');
4
+ const { RelaxedHash } = require('./relaxed');
5
+ const { Transform } = require('node:stream');
6
+ const { MessageParser } = require('../message-parser');
5
7
 
6
8
  const dkimBody = (canonicalization, ...options) => {
7
9
  canonicalization = (canonicalization || 'simple/simple').toString().split('/').pop().toLowerCase().trim();
@@ -18,4 +20,72 @@ const dkimBody = (canonicalization, ...options) => {
18
20
  }
19
21
  };
20
22
 
21
- module.exports = { dkimBody };
23
+ class MessageHasher extends MessageParser {
24
+ constructor(canonicalization, ...options) {
25
+ super();
26
+ this.hasher = dkimBody(canonicalization, ...options);
27
+ this.bodyHash = null;
28
+ }
29
+
30
+ async nextChunk(chunk) {
31
+ this.hasher.update(chunk);
32
+ }
33
+
34
+ async finalChunk() {
35
+ this.bodyHash = this.hasher.digest('base64');
36
+ }
37
+ }
38
+
39
+ class BodyHashStream extends Transform {
40
+ constructor(canonicalization, ...options) {
41
+ super();
42
+
43
+ this.finished = false;
44
+ this.finishCb = null;
45
+
46
+ this.messageHasher = new MessageHasher(canonicalization, ...options);
47
+ this.bodyHash = null;
48
+ this.messageHasher.once('finish', () => this.finishHashing());
49
+ this.messageHasher.once('end', () => this.finishHashing());
50
+ this.messageHasher.once('error', err => this.destroy(err));
51
+ }
52
+
53
+ finishHashing() {
54
+ if (this.finished || !this.finishCb) {
55
+ return;
56
+ }
57
+ this.finished = true;
58
+ let done = this.finishCb;
59
+ this.finishCb = null;
60
+
61
+ this.bodyHash = this.messageHasher.bodyHash;
62
+ this.emit('hash', this.bodyHash);
63
+
64
+ done();
65
+ }
66
+
67
+ _transform(chunk, encoding, done) {
68
+ if (!chunk || !chunk.length) {
69
+ return done();
70
+ }
71
+
72
+ if (typeof chunk === 'string') {
73
+ chunk = Buffer.from(chunk, encoding);
74
+ }
75
+
76
+ if (this.messageHasher.write(chunk) === false) {
77
+ // wait for drain
78
+ return this.messageHasher.once('drain', done);
79
+ }
80
+
81
+ this.push(chunk);
82
+ done();
83
+ }
84
+
85
+ _flush(done) {
86
+ this.finishCb = done;
87
+ this.messageHasher.end();
88
+ }
89
+ }
90
+
91
+ module.exports = { dkimBody, BodyHashStream };
package/man/mailauth.1 CHANGED
@@ -1,4 +1,4 @@
1
- .TH "MAILAUTH" "1" "October 2024" "v4.7.0" "Mailauth Help"
1
+ .TH "MAILAUTH" "1" "October 2024" "v4.7.1" "Mailauth Help"
2
2
  .SH "NAME"
3
3
  \fBmailauth\fR
4
4
  .QP
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mailauth",
3
- "version": "4.7.0",
3
+ "version": "4.7.1",
4
4
  "description": "Email authentication library for Node.js",
5
5
  "main": "lib/mailauth.js",
6
6
  "scripts": {