nodemailer 10.4.1 → 10.6.0
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 +26 -0
- package/README.md +25 -0
- package/dist/cjs/dkim/sign.js +2 -2
- package/dist/cjs/errors.d.ts +2 -0
- package/dist/cjs/errors.js +11 -1
- package/dist/cjs/fetch/cookies.js +4 -1
- package/dist/cjs/json-transport/index.js +2 -0
- package/dist/cjs/mailer/index.d.ts +5 -0
- package/dist/cjs/mailer/index.js +56 -4
- package/dist/cjs/mailer/mail-message.d.ts +10 -0
- package/dist/cjs/mime-funcs/index.d.ts +2 -1
- package/dist/cjs/mime-funcs/index.js +72 -2
- package/dist/cjs/mime-node/index.js +1 -79
- package/dist/cjs/package-info.d.ts +1 -1
- package/dist/cjs/package-info.js +1 -1
- package/dist/cjs/shared/index.d.ts +23 -0
- package/dist/cjs/shared/index.js +79 -0
- package/dist/cjs/smtp-connection/index.d.ts +3 -0
- package/dist/cjs/smtp-connection/index.js +17 -3
- package/dist/cjs/smtp-pool/index.d.ts +1 -0
- package/dist/cjs/smtp-pool/index.js +57 -6
- package/dist/cjs/smtp-pool/pool-resource.js +26 -4
- package/dist/cjs/smtp-transport/index.d.ts +1 -0
- package/dist/cjs/smtp-transport/index.js +47 -35
- package/dist/esm/dkim/sign.js +2 -2
- package/dist/esm/errors.d.ts +2 -0
- package/dist/esm/errors.js +9 -0
- package/dist/esm/fetch/cookies.js +4 -1
- package/dist/esm/json-transport/index.js +2 -0
- package/dist/esm/mailer/index.d.ts +5 -0
- package/dist/esm/mailer/index.js +56 -4
- package/dist/esm/mailer/mail-message.d.ts +10 -0
- package/dist/esm/mime-funcs/index.d.ts +2 -1
- package/dist/esm/mime-funcs/index.js +72 -2
- package/dist/esm/mime-node/index.js +1 -79
- package/dist/esm/package-info.d.ts +1 -1
- package/dist/esm/package-info.js +1 -1
- package/dist/esm/shared/index.d.ts +23 -0
- package/dist/esm/shared/index.js +78 -0
- package/dist/esm/smtp-connection/index.d.ts +3 -0
- package/dist/esm/smtp-connection/index.js +17 -3
- package/dist/esm/smtp-pool/index.d.ts +1 -0
- package/dist/esm/smtp-pool/index.js +57 -6
- package/dist/esm/smtp-pool/pool-resource.js +26 -4
- package/dist/esm/smtp-transport/index.d.ts +1 -0
- package/dist/esm/smtp-transport/index.js +47 -35
- package/package.json +11 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## [10.6.0](https://github.com/nodemailer/nodemailer/compare/v10.5.0...v10.6.0) (2026-11-15)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **smtp:** add configurable socketCloseTimeout ([#1916](https://github.com/nodemailer/nodemailer/issues/1916)) ([7f04d0b](https://github.com/nodemailer/nodemailer/commit/7f04d0b78e887191c89775cf4a3063462b222aad)), closes [#1915](https://github.com/nodemailer/nodemailer/issues/1915)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* let Set-Cookie Max-Age take precedence over Expires ([#1917](https://github.com/nodemailer/nodemailer/issues/1917)) ([d6d6d44](https://github.com/nodemailer/nodemailer/commit/d6d6d44f5fbdf61936032d8865a1312c89c1804e))
|
|
14
|
+
* **smtp-connection:** close the TLS socket of an upgraded connection on Node 27 ([4135015](https://github.com/nodemailer/nodemailer/commit/4135015175398aaad5ac6e1866e91a758c432417))
|
|
15
|
+
|
|
16
|
+
## [10.5.0](https://github.com/nodemailer/nodemailer/compare/v10.4.1...v10.5.0) (2026-11-10)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* **smtp:** support AbortSignal for individual sends ([#1911](https://github.com/nodemailer/nodemailer/issues/1911)) ([66387ed](https://github.com/nodemailer/nodemailer/commit/66387ed6f4bd26208b944b74b7329201ad77377b)), closes [#1910](https://github.com/nodemailer/nodemailer/issues/1910)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* **dkim:** encode the d= domain the same way as the address headers ([#1908](https://github.com/nodemailer/nodemailer/issues/1908)) ([4ebf03f](https://github.com/nodemailer/nodemailer/commit/4ebf03fba33a96118c10afa340ce895a00549148))
|
|
27
|
+
* **mime-funcs:** encode header text that would be decoded as an invalid encoded word ([#1912](https://github.com/nodemailer/nodemailer/issues/1912)) ([7a7b942](https://github.com/nodemailer/nodemailer/commit/7a7b9427b632d8785190747ae2c62e88e77bc837))
|
|
28
|
+
|
|
3
29
|
## [10.4.1](https://github.com/nodemailer/nodemailer/compare/v10.4.0...v10.4.1) (2026-11-10)
|
|
4
30
|
|
|
5
31
|
|
package/README.md
CHANGED
|
@@ -14,6 +14,31 @@ See [nodemailer.com](https://nodemailer.com/) for documentation and terms.
|
|
|
14
14
|
|
|
15
15
|
Nodemailer targets Node.js 20 and later. The ES module build also runs on [Bun](https://bun.sh/) (tested against the latest release) and on [Cloudflare Workers](https://developers.cloudflare.com/workers/) with the `nodejs_compat` compatibility flag. On Workers only the SMTP based transports apply, `sendmail` needs a child process, and the runtime does not allow turning certificate validation off, so `tls.rejectUnauthorized: false` fails there with an error.
|
|
16
16
|
|
|
17
|
+
## Cancelling an individual SMTP send
|
|
18
|
+
|
|
19
|
+
Pass an `AbortSignal` in the message options to cancel one `sendMail()` call:
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
await transporter.sendMail({
|
|
23
|
+
from: 'sender@example.com',
|
|
24
|
+
to: 'recipient@example.com',
|
|
25
|
+
text: 'Hello',
|
|
26
|
+
signal: AbortSignal.timeout(30_000)
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This is supported by SMTP and pooled SMTP transports. A pre-aborted signal prevents processing; aborting later stops subsequent plugin processing, removes a queued message, or closes the SMTP connection assigned to that message. Other deliveries in the pool can continue. Both promise and callback forms report an error named `AbortError`, with `code: 'EABORT'` and the signal's reason as `cause`. The signal listener is removed when the send finishes.
|
|
31
|
+
|
|
32
|
+
Cancellation stops local processing; it does not prove that the SMTP server has not already accepted the message. Do not retry a cancelled send automatically on that assumption.
|
|
33
|
+
|
|
34
|
+
Work already started by a plugin or a custom `getSocket` hook requires that code's cooperation to stop. Nodemailer ignores late plugin completion and destroys a socket handed back after cancellation. Plugins can read `mail.data.signal` to cancel their own work.
|
|
35
|
+
|
|
36
|
+
Other bundled transports (stream, JSON, sendmail and SES) ignore the signal once the message is handed to them, so the message is sent normally. A signal that is already aborted, or aborts while plugins run, still cancels the send with `EABORT` on every transport, as that happens before the transport is called. A `signal` value that is not an `AbortSignal` fails the send with `ECONFIG`. Custom transports can opt in with `supportsAbortSignal: true`; their `send()` must register its abort listener synchronously, check for a pre-aborted signal, stop the work it owns, invoke its callback once, and remove the listener on completion.
|
|
37
|
+
|
|
38
|
+
## SMTP socket close timeout
|
|
39
|
+
|
|
40
|
+
When an SMTP connection closes, Nodemailer ends the socket and destroys it if the server has not closed its side within `socketCloseTimeout` milliseconds (default 5000). Set it to `0` to destroy the socket right away. This applies to SMTP and pooled SMTP, including aborted sends and `transporter.close({ force: true })`. It does not tell you whether the server accepted a message that was in flight.
|
|
41
|
+
|
|
17
42
|
## Having an issue?
|
|
18
43
|
|
|
19
44
|
#### First review the docs
|
package/dist/cjs/dkim/sign.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const
|
|
39
|
+
const shared = __importStar(require("../shared/index.js"));
|
|
40
40
|
const mimeFuncs = __importStar(require("../mime-funcs/index.js"));
|
|
41
41
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
42
42
|
const errors = __importStar(require("../errors.js"));
|
|
@@ -103,7 +103,7 @@ function generateDKIMHeader(domainName, keySelector, fieldNames, hashAlgo, bodyH
|
|
|
103
103
|
'v=1',
|
|
104
104
|
'a=rsa-' + hashAlgo,
|
|
105
105
|
'c=relaxed/relaxed',
|
|
106
|
-
'd=' +
|
|
106
|
+
'd=' + shared.normalizeDomain(cleanTagValue(domainName), false),
|
|
107
107
|
'q=dns/txt',
|
|
108
108
|
's=' + cleanTagValue(keySelector),
|
|
109
109
|
'bh=' + bodyHash,
|
package/dist/cjs/errors.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare const ERROR_CODES: {
|
|
|
23
23
|
readonly EMESSAGE: "Message delivery error";
|
|
24
24
|
readonly EOTP: "Invalid one-time passcode data (otp option)";
|
|
25
25
|
readonly ESTREAM: "Stream processing error";
|
|
26
|
+
readonly EABORT: "Message sending aborted";
|
|
26
27
|
readonly EAUTH: "Authentication failed";
|
|
27
28
|
readonly ENOAUTH: "Authentication credentials not provided";
|
|
28
29
|
readonly EOAUTH2: "OAuth2 token generation or refresh error";
|
|
@@ -51,6 +52,7 @@ export declare const EENVELOPE = "EENVELOPE";
|
|
|
51
52
|
export declare const EMESSAGE = "EMESSAGE";
|
|
52
53
|
export declare const EOTP = "EOTP";
|
|
53
54
|
export declare const ESTREAM = "ESTREAM";
|
|
55
|
+
export declare const EABORT = "EABORT";
|
|
54
56
|
export declare const EAUTH = "EAUTH";
|
|
55
57
|
export declare const ENOAUTH = "ENOAUTH";
|
|
56
58
|
export declare const EOAUTH2 = "EOAUTH2";
|
package/dist/cjs/errors.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* err.code = errors.ECONNECTION;
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.ERR_ACCESS_DENIED = exports.isPermanentResponseCode = exports.isTransientError = exports.EFETCH = exports.EURLACCESS = exports.EFILEACCESS = exports.EPROXY = exports.ECONFIG = exports.ESES = exports.ESENDMAIL = exports.EMAXRECIPIENTS = exports.EMAXLIMIT = exports.EOAUTH2 = exports.ENOAUTH = exports.EAUTH = exports.ESTREAM = exports.EOTP = exports.EMESSAGE = exports.EENVELOPE = exports.EPROTOCOL = exports.EREQUIRETLS = exports.ETLS = exports.EDNS = exports.ESOCKET = exports.ETIMEDOUT = exports.ECONNECTION = exports.ERROR_CODES = void 0;
|
|
13
|
+
exports.ERR_ACCESS_DENIED = exports.isPermanentResponseCode = exports.isTransientError = exports.createAbortError = exports.EFETCH = exports.EURLACCESS = exports.EFILEACCESS = exports.EPROXY = exports.ECONFIG = exports.ESES = exports.ESENDMAIL = exports.EMAXRECIPIENTS = exports.EMAXLIMIT = exports.EOAUTH2 = exports.ENOAUTH = exports.EAUTH = exports.EABORT = exports.ESTREAM = exports.EOTP = exports.EMESSAGE = exports.EENVELOPE = exports.EPROTOCOL = exports.EREQUIRETLS = exports.ETLS = exports.EDNS = exports.ESOCKET = exports.ETIMEDOUT = exports.ECONNECTION = exports.ERROR_CODES = void 0;
|
|
14
14
|
/**
|
|
15
15
|
* Error code descriptions for documentation and debugging
|
|
16
16
|
*/
|
|
@@ -29,6 +29,7 @@ exports.ERROR_CODES = {
|
|
|
29
29
|
EMESSAGE: 'Message delivery error',
|
|
30
30
|
EOTP: 'Invalid one-time passcode data (otp option)',
|
|
31
31
|
ESTREAM: 'Stream processing error',
|
|
32
|
+
EABORT: 'Message sending aborted',
|
|
32
33
|
// Authentication errors
|
|
33
34
|
EAUTH: 'Authentication failed',
|
|
34
35
|
ENOAUTH: 'Authentication credentials not provided',
|
|
@@ -58,6 +59,7 @@ exports.EENVELOPE = 'EENVELOPE';
|
|
|
58
59
|
exports.EMESSAGE = 'EMESSAGE';
|
|
59
60
|
exports.EOTP = 'EOTP';
|
|
60
61
|
exports.ESTREAM = 'ESTREAM';
|
|
62
|
+
exports.EABORT = 'EABORT';
|
|
61
63
|
exports.EAUTH = 'EAUTH';
|
|
62
64
|
exports.ENOAUTH = 'ENOAUTH';
|
|
63
65
|
exports.EOAUTH2 = 'EOAUTH2';
|
|
@@ -70,6 +72,14 @@ exports.EPROXY = 'EPROXY';
|
|
|
70
72
|
exports.EFILEACCESS = 'EFILEACCESS';
|
|
71
73
|
exports.EURLACCESS = 'EURLACCESS';
|
|
72
74
|
exports.EFETCH = 'EFETCH';
|
|
75
|
+
/** Creates the error reported when a caller cancels an individual send. @internal */
|
|
76
|
+
const createAbortError = (signal) => {
|
|
77
|
+
const err = new Error('Message sending aborted', { cause: signal.reason });
|
|
78
|
+
err.name = 'AbortError';
|
|
79
|
+
err.code = exports.EABORT;
|
|
80
|
+
return err;
|
|
81
|
+
};
|
|
82
|
+
exports.createAbortError = createAbortError;
|
|
73
83
|
/**
|
|
74
84
|
* Tells whether the error ended the connection rather than rejected what was sent over it
|
|
75
85
|
*/
|
|
@@ -131,6 +131,7 @@ class Cookies {
|
|
|
131
131
|
parse(cookieStr) {
|
|
132
132
|
const cookie = {};
|
|
133
133
|
let hasNameValue = false;
|
|
134
|
+
let hasMaxAge = false;
|
|
134
135
|
(cookieStr || '')
|
|
135
136
|
.toString()
|
|
136
137
|
.split(';')
|
|
@@ -158,7 +159,8 @@ class Cookies {
|
|
|
158
159
|
case 'expires': {
|
|
159
160
|
const expires = new Date(value);
|
|
160
161
|
// ignore date if can not parse it
|
|
161
|
-
if (expires.toString() !== 'Invalid Date') {
|
|
162
|
+
if (expires.toString() !== 'Invalid Date' && !hasMaxAge) {
|
|
163
|
+
// Max-Age has precedence when both attributes are present (RFC 6265 5.3)
|
|
162
164
|
cookie.expires = expires;
|
|
163
165
|
}
|
|
164
166
|
break;
|
|
@@ -175,6 +177,7 @@ class Cookies {
|
|
|
175
177
|
break;
|
|
176
178
|
case 'max-age':
|
|
177
179
|
cookie.expires = new Date(Date.now() + (Number(value) || 0) * 1000);
|
|
180
|
+
hasMaxAge = true;
|
|
178
181
|
break;
|
|
179
182
|
case 'secure':
|
|
180
183
|
cookie.secure = true;
|
|
@@ -83,6 +83,8 @@ class JSONTransport {
|
|
|
83
83
|
}
|
|
84
84
|
delete data.envelope;
|
|
85
85
|
delete data.normalizedHeaders;
|
|
86
|
+
// the per-message AbortSignal is not message data
|
|
87
|
+
delete data.signal;
|
|
86
88
|
// the message field is the object itself with skipEncoding, the
|
|
87
89
|
// createTransport overload for that option types the result accordingly
|
|
88
90
|
return done(null, {
|
|
@@ -112,6 +112,11 @@ export interface MailMeta {
|
|
|
112
112
|
* declared on Transport, Transporter and Mail
|
|
113
113
|
*/
|
|
114
114
|
export interface Transport<T = SentMessageInfo, D extends TransportOptions = TransportOptions> {
|
|
115
|
+
/**
|
|
116
|
+
* Set only if send() cancels its own work on mail.data.signal and removes its signal listener
|
|
117
|
+
* when finished. Without it the signal is still honored up to dispatch, then ignored.
|
|
118
|
+
*/
|
|
119
|
+
supportsAbortSignal?: boolean | undefined;
|
|
115
120
|
/** Transport name, used for logging */
|
|
116
121
|
name: string;
|
|
117
122
|
/** Transport version, used for logging */
|
package/dist/cjs/mailer/index.js
CHANGED
|
@@ -56,6 +56,16 @@ const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
|
56
56
|
* asks a server to accept 100, so a real send is bounded far below this.
|
|
57
57
|
*/
|
|
58
58
|
const DEFAULT_MAX_RECIPIENTS = 100000;
|
|
59
|
+
/**
|
|
60
|
+
* Duck-typed so that signals from another realm or a polyfill are accepted as well
|
|
61
|
+
*/
|
|
62
|
+
function isAbortSignal(value) {
|
|
63
|
+
return (typeof value === 'object' &&
|
|
64
|
+
value !== null &&
|
|
65
|
+
'aborted' in value &&
|
|
66
|
+
typeof value.addEventListener === 'function' &&
|
|
67
|
+
typeof value.removeEventListener === 'function');
|
|
68
|
+
}
|
|
59
69
|
/**
|
|
60
70
|
* Creates an object for exposing the Mail API
|
|
61
71
|
*
|
|
@@ -157,11 +167,43 @@ class Mail extends node_events_1.EventEmitter {
|
|
|
157
167
|
this.getSocket = false;
|
|
158
168
|
}
|
|
159
169
|
const mail = new mail_message_js_1.default(this, data);
|
|
170
|
+
const signalOption = mail.data.signal;
|
|
171
|
+
const signal = isAbortSignal(signalOption) ? signalOption : undefined;
|
|
172
|
+
let settled = false;
|
|
173
|
+
const removeAbortListener = () => signal?.removeEventListener('abort', onAbort);
|
|
174
|
+
const finish = (err, info) => {
|
|
175
|
+
if (settled) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
settled = true;
|
|
179
|
+
removeAbortListener();
|
|
180
|
+
if (err) {
|
|
181
|
+
mail.releaseStreams();
|
|
182
|
+
}
|
|
183
|
+
done(err, info);
|
|
184
|
+
};
|
|
160
185
|
// a failed message is not going to be read anymore, release its content streams
|
|
161
186
|
const fail = (err) => {
|
|
162
|
-
|
|
163
|
-
done(err);
|
|
187
|
+
finish(err);
|
|
164
188
|
};
|
|
189
|
+
function onAbort() {
|
|
190
|
+
fail(errors.createAbortError(signal));
|
|
191
|
+
}
|
|
192
|
+
if (signalOption !== undefined && signalOption !== null && !signal) {
|
|
193
|
+
const err = new Error('The signal option must be an AbortSignal');
|
|
194
|
+
err.code = errors.ECONFIG;
|
|
195
|
+
setImmediate(() => fail(err));
|
|
196
|
+
return promise;
|
|
197
|
+
}
|
|
198
|
+
// Mail handles a pre-aborted signal and cancellation during plugin processing for every
|
|
199
|
+
// transport; a transport without supportsAbortSignal ignores the signal once it is called
|
|
200
|
+
if (signal) {
|
|
201
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
202
|
+
if (signal.aborted) {
|
|
203
|
+
setImmediate(onAbort);
|
|
204
|
+
return promise;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
165
207
|
this.logger.debug({
|
|
166
208
|
tnx: 'transport',
|
|
167
209
|
name: this.transporter.name,
|
|
@@ -169,6 +211,9 @@ class Mail extends node_events_1.EventEmitter {
|
|
|
169
211
|
action: 'send'
|
|
170
212
|
}, 'Sending mail using %s/%s', this.transporter.name, this.transporter.version);
|
|
171
213
|
this._processPlugins('compile', mail, err => {
|
|
214
|
+
if (settled) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
172
217
|
if (err) {
|
|
173
218
|
this.logger.error({
|
|
174
219
|
err,
|
|
@@ -206,6 +251,9 @@ class Mail extends node_events_1.EventEmitter {
|
|
|
206
251
|
return fail(err);
|
|
207
252
|
}
|
|
208
253
|
this._processPlugins('stream', mail, err => {
|
|
254
|
+
if (settled) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
209
257
|
if (err) {
|
|
210
258
|
this.logger.error({
|
|
211
259
|
err,
|
|
@@ -225,16 +273,17 @@ class Mail extends node_events_1.EventEmitter {
|
|
|
225
273
|
return dkim.sign(input, mail.data._dkim);
|
|
226
274
|
});
|
|
227
275
|
}
|
|
276
|
+
// The transport takes ownership of cancellation from here, including queued work.
|
|
277
|
+
removeAbortListener();
|
|
228
278
|
this.transporter.send(mail, (...args) => {
|
|
229
279
|
if (args[0]) {
|
|
230
|
-
mail.releaseStreams();
|
|
231
280
|
this.logger.error({
|
|
232
281
|
err: args[0],
|
|
233
282
|
tnx: 'transport',
|
|
234
283
|
action: 'send'
|
|
235
284
|
}, 'Send Error: %s', args[0].message);
|
|
236
285
|
}
|
|
237
|
-
|
|
286
|
+
finish(...args);
|
|
238
287
|
});
|
|
239
288
|
});
|
|
240
289
|
});
|
|
@@ -264,6 +313,9 @@ class Mail extends node_events_1.EventEmitter {
|
|
|
264
313
|
let pos = 0;
|
|
265
314
|
let block = 'default';
|
|
266
315
|
const processPlugins = () => {
|
|
316
|
+
if (mail.data.signal?.aborted) {
|
|
317
|
+
return callback(errors.createAbortError(mail.data.signal));
|
|
318
|
+
}
|
|
267
319
|
let curplugins = block === 'default' ? defaultPlugins : userPlugins;
|
|
268
320
|
if (pos >= curplugins.length) {
|
|
269
321
|
if (block === 'default' && userPlugins.length) {
|
|
@@ -13,6 +13,16 @@ import type { SentMessageInfo } from './index.js';
|
|
|
13
13
|
* tree is built from, the fields below are the ones the mailer reads on top of those
|
|
14
14
|
*/
|
|
15
15
|
export interface SendMailOptions extends MailComposerOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Cancel this send, including waiting for plugins or in an SMTP pool queue.
|
|
18
|
+
* Plugins must cooperate with the signal to stop their own work already in progress.
|
|
19
|
+
* Supported by SMTP, pooled SMTP and transports declaring supportsAbortSignal. Other
|
|
20
|
+
* transports ignore the signal once the message is handed to them; a signal that is
|
|
21
|
+
* already aborted, or aborts during plugin processing, still cancels the send.
|
|
22
|
+
* Fails with AbortError/EABORT on cancellation, ECONFIG if the value is not an AbortSignal.
|
|
23
|
+
* Aborting does not prove that the server has not already accepted the message.
|
|
24
|
+
*/
|
|
25
|
+
signal?: AbortSignal | undefined;
|
|
16
26
|
/** DKIM signing options for this message, used instead of the ones of the transporter */
|
|
17
27
|
dkim?: DKIMOptions | undefined;
|
|
18
28
|
/** Extra DKIM options for this message, merged over the options of the signer. The SES transport sets skipFields here, the option is not meant for callers */
|
|
@@ -74,7 +74,8 @@ export declare function hasLongerLines(str: string, lineLength: number): boolean
|
|
|
74
74
|
*/
|
|
75
75
|
export declare function encodeWord(data: string | Buffer, mimeWordEncoding?: string, maxLength?: number): string;
|
|
76
76
|
/**
|
|
77
|
-
* Finds word sequences with non ascii text and
|
|
77
|
+
* Finds word sequences with non ascii text, and words that look like an invalid encoded-word,
|
|
78
|
+
* and converts these to mime words. A valid encoded-word is passed through as it is.
|
|
78
79
|
*
|
|
79
80
|
* @param value String to be encoded
|
|
80
81
|
* @param mimeWordEncoding='Q' Encoding for the mime word, either Q or B
|
|
@@ -181,8 +181,75 @@ function encodeWord(data, mimeWordEncoding, maxLength) {
|
|
|
181
181
|
}
|
|
182
182
|
return '=?' + toCharset + '?' + mimeWordEncoding + '?' + encodedStr + (encodedStr.substr(-2) === '?=' ? '' : '?=');
|
|
183
183
|
}
|
|
184
|
+
// An encoded-word as RFC 2047 section 2 spells it: a charset token (with an optional RFC 2231
|
|
185
|
+
// language), B or Q, and encoded text without '?' or whitespace. None of the parts can hold the
|
|
186
|
+
// '?' that separates them, so the pattern never backtracks
|
|
187
|
+
const VALID_ENCODED_WORD = /^=\?[^\s()<>@,;:"/[\]?.=]+\?[BbQq]\?[^?\s]+\?=$/;
|
|
188
|
+
// What a lenient decoder reads as an encoded-word: libmime and Python decode
|
|
189
|
+
// '=?utf-8?Q?a b?=' across the space as well. Applied sticky at a '=?', and every part stops
|
|
190
|
+
// at the next '?', so it does not backtrack either
|
|
191
|
+
const LENIENT_ENCODED_WORD = /[=]\?[^?]*\?[BbQq]\?[^?]*\?=/y;
|
|
184
192
|
/**
|
|
185
|
-
*
|
|
193
|
+
* Marks the text a receiver would read as an encoded-word when it is not one valid encoded-word
|
|
194
|
+
* on its own. RFC 2047 section 7 requires that a word beginning with '=?' and ending with '?='
|
|
195
|
+
* is a valid encoded-word, and decoders also decode a look-alike that spans whitespace, so
|
|
196
|
+
* '=?utf-8?X?x?=' and 'see =?utf-8?Q?a b?= here' read differently on every receiver. A valid
|
|
197
|
+
* encoded-word is left alone, which is what lets a caller pass a value that is already encoded,
|
|
198
|
+
* as most other mail libraries do.
|
|
199
|
+
*
|
|
200
|
+
* The bounds of the word around each '=?' are found once per word and reused, walking back to
|
|
201
|
+
* the start of a long word from every '=?' it holds would be quadratic.
|
|
202
|
+
*
|
|
203
|
+
* @param value String to look in
|
|
204
|
+
* @param range The first and the last offset that needs encoding so far, -1 for none
|
|
205
|
+
* @return The range, widened to cover the words of every invalid look-alike
|
|
206
|
+
*/
|
|
207
|
+
function _markInvalidEncodedWords(value, range) {
|
|
208
|
+
const len = value.length;
|
|
209
|
+
const isSpace = (pos) => /\s/.test(value.charAt(pos));
|
|
210
|
+
// the word last looked at, its start and the offset just past it
|
|
211
|
+
let wordStart = 0;
|
|
212
|
+
let wordEnd = -1;
|
|
213
|
+
const wordAt = (pos) => {
|
|
214
|
+
if (pos < wordEnd) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
// the previous word ended at whitespace, so the walk back stops before reaching it
|
|
218
|
+
wordStart = pos;
|
|
219
|
+
while (wordStart > 0 && !isSpace(wordStart - 1)) {
|
|
220
|
+
wordStart--;
|
|
221
|
+
}
|
|
222
|
+
wordEnd = pos;
|
|
223
|
+
while (wordEnd < len && !isSpace(wordEnd)) {
|
|
224
|
+
wordEnd++;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
let pos = value.indexOf('=?');
|
|
228
|
+
while (pos >= 0) {
|
|
229
|
+
wordAt(pos);
|
|
230
|
+
const start = wordStart;
|
|
231
|
+
LENIENT_ENCODED_WORD.lastIndex = pos;
|
|
232
|
+
const match = LENIENT_ENCODED_WORD.exec(value);
|
|
233
|
+
const end = match ? pos + match[0].length : wordEnd;
|
|
234
|
+
if (match && end > wordEnd) {
|
|
235
|
+
// the look-alike runs across whitespace, on to the word it ends in
|
|
236
|
+
wordAt(end - 1);
|
|
237
|
+
}
|
|
238
|
+
const word = value.substring(start, wordEnd);
|
|
239
|
+
// without a match, a word that begins with '=?' and ends with '?=' is still invalid
|
|
240
|
+
const looksLike = match ? true : start === pos && word.length >= 4 && word.endsWith('?=');
|
|
241
|
+
const valid = start === pos && wordEnd === end && word.length <= 75 && VALID_ENCODED_WORD.test(word);
|
|
242
|
+
if (looksLike && !valid) {
|
|
243
|
+
range[0] = range[0] < 0 ? start : Math.min(range[0], start);
|
|
244
|
+
range[1] = Math.max(range[1], wordEnd - 1);
|
|
245
|
+
}
|
|
246
|
+
pos = value.indexOf('=?', match ? end : pos + 2);
|
|
247
|
+
}
|
|
248
|
+
return range;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Finds word sequences with non ascii text, and words that look like an invalid encoded-word,
|
|
252
|
+
* and converts these to mime words. A valid encoded-word is passed through as it is.
|
|
186
253
|
*
|
|
187
254
|
* @param value String to be encoded
|
|
188
255
|
* @param mimeWordEncoding='Q' Encoding for the mime word, either Q or B
|
|
@@ -206,11 +273,14 @@ function encodeWords(value, mimeWordEncoding, maxLength, encodeAll) {
|
|
|
206
273
|
lastSpecial = i;
|
|
207
274
|
}
|
|
208
275
|
}
|
|
276
|
+
if (value.indexOf('=?') >= 0) {
|
|
277
|
+
[firstSpecial, lastSpecial] = _markInvalidEncodedWords(value, [firstSpecial, lastSpecial]);
|
|
278
|
+
}
|
|
209
279
|
if (firstSpecial < 0) {
|
|
210
280
|
return value;
|
|
211
281
|
}
|
|
212
282
|
if (encodeAll) {
|
|
213
|
-
//
|
|
283
|
+
// the value needs encoding and it is requested to encode everything
|
|
214
284
|
return encodeWord(value, mimeWordEncoding, maxLength);
|
|
215
285
|
}
|
|
216
286
|
// encode from the start of the word holding the first such character to the end of the
|
|
@@ -39,10 +39,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
41
41
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
42
|
-
const punycode = __importStar(require("../punycode/index.js"));
|
|
43
42
|
const node_stream_1 = require("node:stream");
|
|
44
43
|
const shared = __importStar(require("../shared/index.js"));
|
|
45
|
-
const node_url_1 = __importDefault(require("node:url"));
|
|
46
44
|
const mimeFuncs = __importStar(require("../mime-funcs/index.js"));
|
|
47
45
|
const qp = __importStar(require("../qp/index.js"));
|
|
48
46
|
const base64 = __importStar(require("../base64/index.js"));
|
|
@@ -93,20 +91,6 @@ function stripWhitespaceInAngleBrackets(value) {
|
|
|
93
91
|
}
|
|
94
92
|
return result + value.slice(pos);
|
|
95
93
|
}
|
|
96
|
-
// domainToASCII and domainToUnicode are WHATWG host parsers rather than plain IDNA
|
|
97
|
-
// mappers, so they do more than map: they cut the host at '/', '\\', '?' and '#', drop C0
|
|
98
|
-
// controls, and percent-decode. Handing them 'evil.example/mail.corp.example' returns the
|
|
99
|
-
// deliverable 'evil.example', which would turn a value the bundled codec leaves as
|
|
100
|
-
// unroutable garbage into mail for a domain the sender never named. None of these
|
|
101
|
-
// characters are legal in a domain, so keep them away from the mapper.
|
|
102
|
-
const URL_PARSER_UNSAFE = /[/\\?#%\x00-\x20\x7F]/;
|
|
103
|
-
// RFC 1035 bounds a label at 63 octets and a domain at 253. An A-label is never shorter than
|
|
104
|
-
// the code points it encodes, so anything past these bounds could not have become a valid
|
|
105
|
-
// domain whichever way it is encoded. The bundled codec is super-linear in the length of a
|
|
106
|
-
// label, a 60 KB label of distinct code points took seconds to encode, several times per
|
|
107
|
-
// address, so it is only handed what could be a domain
|
|
108
|
-
const MAX_DOMAIN_LENGTH = 253;
|
|
109
|
-
const MAX_LABEL_LENGTH = 63;
|
|
110
94
|
// pipeline() needs a callback to not throw, the errors it sees reach the last stream anyway
|
|
111
95
|
const PIPELINE_NOOP = () => false;
|
|
112
96
|
// The error a node streaming into an output that was destroyed stops with
|
|
@@ -115,68 +99,6 @@ function abortedError() {
|
|
|
115
99
|
err.code = errors.ESTREAM;
|
|
116
100
|
return err;
|
|
117
101
|
}
|
|
118
|
-
/**
|
|
119
|
-
* Checks a domain against the DNS length limits, counted in code points per label and in
|
|
120
|
-
* total. The label separators are the ones the bundled codec splits on.
|
|
121
|
-
*
|
|
122
|
-
* @param domain Domain to check
|
|
123
|
-
* @return true if a label or the domain as a whole is too long to be a valid domain
|
|
124
|
-
*/
|
|
125
|
-
function exceedsDomainLimits(domain) {
|
|
126
|
-
let total = 0;
|
|
127
|
-
let label = 0;
|
|
128
|
-
for (const char of domain) {
|
|
129
|
-
total++;
|
|
130
|
-
if (char === '.' || char === '。' || char === '.' || char === '。') {
|
|
131
|
-
label = 0;
|
|
132
|
-
}
|
|
133
|
-
else if (++label > MAX_LABEL_LENGTH) {
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return total > MAX_DOMAIN_LENGTH;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Encodes a domain the way browsers, the WHATWG URL Standard and DNS facing resolvers do,
|
|
141
|
-
* which is with UTS-46 mapping applied before the Punycode step.
|
|
142
|
-
*
|
|
143
|
-
* The bundled codec is plain RFC 3492 and maps nothing, so it disagrees with every
|
|
144
|
-
* conformant parser on any domain holding a mapped or ignored code point. An invisible
|
|
145
|
-
* U+00AD in 'compa\u00ADny.com' encoded to 'xn--company-pka.com' where a validator reads
|
|
146
|
-
* 'company.com', which let an allow-listed domain be checked and a different one mailed.
|
|
147
|
-
*
|
|
148
|
-
* Anything the URL parser does not accept as a hostname, an address literal such as
|
|
149
|
-
* '[127.0.0.1]' included, comes back empty and falls through to the bundled codec, which
|
|
150
|
-
* leaves those as they were supplied apart from lowercasing them.
|
|
151
|
-
*
|
|
152
|
-
* The mapper gets the domain as supplied, since UTS-46 does its own case mapping and
|
|
153
|
-
* toLowerCase() differs from it: it turns U+1E9E into U+00DF where Node 20 and 22 map it
|
|
154
|
-
* to 'ss', and a word-final U+03A3 into U+03C2 where UTS-46 gives U+03C3. Lowercasing
|
|
155
|
-
* first sent 'user@stra\u1E9Ee.de', which a validator reads as strasse.de, to xn--strae-oqa.de.
|
|
156
|
-
*
|
|
157
|
-
* @param domain Domain to encode
|
|
158
|
-
* @param toUnicode Return the U-label form instead of the A-label form
|
|
159
|
-
* @return Encoded domain
|
|
160
|
-
*/
|
|
161
|
-
function normalizeDomain(domain, toUnicode) {
|
|
162
|
-
// domainToASCII and domainToUnicode landed in Node 7, the bundled codec covers Node 6
|
|
163
|
-
if (typeof node_url_1.default.domainToASCII === 'function' && typeof node_url_1.default.domainToUnicode === 'function' && !URL_PARSER_UNSAFE.test(domain)) {
|
|
164
|
-
// The U-label form is decoded from the A-label form rather than from the input:
|
|
165
|
-
// Deno's domainToASCII returns an empty string for a label it cannot decode, while
|
|
166
|
-
// its domainToUnicode returns the label with U+FFFD in place of the bad part
|
|
167
|
-
const ascii = node_url_1.default.domainToASCII(domain);
|
|
168
|
-
const mapped = ascii && toUnicode ? node_url_1.default.domainToUnicode(ascii) : ascii;
|
|
169
|
-
if (mapped) {
|
|
170
|
-
return mapped;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
domain = domain.toLowerCase();
|
|
174
|
-
if (exceedsDomainLimits(domain)) {
|
|
175
|
-
// too long to be a domain whichever way it is encoded, keep it as supplied
|
|
176
|
-
return domain;
|
|
177
|
-
}
|
|
178
|
-
return toUnicode ? punycode.toUnicode(domain) : punycode.toASCII(domain);
|
|
179
|
-
}
|
|
180
102
|
/**
|
|
181
103
|
* Removes the characters that must never reach a multipart delimiter line.
|
|
182
104
|
*
|
|
@@ -1544,7 +1466,7 @@ class MimeNode {
|
|
|
1544
1466
|
// symmetry on both sides of the '@' rather than being encoded to an A-label
|
|
1545
1467
|
const smtputf8 = /[\x80-\uFFFF]/.test(user);
|
|
1546
1468
|
try {
|
|
1547
|
-
encodedDomain = normalizeDomain(domain, smtputf8);
|
|
1469
|
+
encodedDomain = shared.normalizeDomain(domain, smtputf8);
|
|
1548
1470
|
}
|
|
1549
1471
|
catch (_err) {
|
|
1550
1472
|
// keep domain as supplied
|
package/dist/cjs/package-info.js
CHANGED
|
@@ -289,3 +289,26 @@ export declare function unreadableStreamError(stream: Readable): NodemailerError
|
|
|
289
289
|
* @param callback Callback function with (err, value)
|
|
290
290
|
*/
|
|
291
291
|
export declare function resolveStream(stream: Readable, callback: (err: Error | null, value?: Buffer) => void): void;
|
|
292
|
+
/**
|
|
293
|
+
* Encodes a domain the way browsers, the WHATWG URL Standard and DNS facing resolvers do,
|
|
294
|
+
* which is with UTS-46 mapping applied before the Punycode step.
|
|
295
|
+
*
|
|
296
|
+
* The bundled codec is plain RFC 3492 and maps nothing, so it disagrees with every
|
|
297
|
+
* conformant parser on any domain holding a mapped or ignored code point. An invisible
|
|
298
|
+
* U+00AD in 'compa\u00ADny.com' encoded to 'xn--company-pka.com' where a validator reads
|
|
299
|
+
* 'company.com', which let an allow-listed domain be checked and a different one mailed.
|
|
300
|
+
*
|
|
301
|
+
* Anything the URL parser does not accept as a hostname, an address literal such as
|
|
302
|
+
* '[127.0.0.1]' included, comes back empty and falls through to the bundled codec, which
|
|
303
|
+
* leaves those as they were supplied apart from lowercasing them.
|
|
304
|
+
*
|
|
305
|
+
* The mapper gets the domain as supplied, since UTS-46 does its own case mapping and
|
|
306
|
+
* toLowerCase() differs from it: it turns U+1E9E into U+00DF where Node 20 and 22 map it
|
|
307
|
+
* to 'ss', and a word-final U+03A3 into U+03C2 where UTS-46 gives U+03C3. Lowercasing
|
|
308
|
+
* first sent 'user@stra\u1E9Ee.de', which a validator reads as strasse.de, to xn--strae-oqa.de.
|
|
309
|
+
*
|
|
310
|
+
* @param domain Domain to encode
|
|
311
|
+
* @param toUnicode Return the U-label form instead of the A-label form
|
|
312
|
+
* @return Encoded domain
|
|
313
|
+
*/
|
|
314
|
+
export declare function normalizeDomain(domain: string, toUnicode: boolean): string;
|