@mavogel/awscdk-rootmail 0.1.42 → 0.1.44
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/.jsii +8 -8
- package/lib/rootmail.js +1 -1
- package/lib/ses-receive.js +1 -1
- package/node_modules/@aws-sdk/checksums/package.json +3 -3
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-cloudwatch-logs/package.json +4 -4
- package/node_modules/@aws-sdk/client-route-53/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-route-53/package.json +4 -4
- package/node_modules/@aws-sdk/client-s3/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-s3/package.json +7 -7
- package/node_modules/@aws-sdk/client-ses/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-ses/package.json +4 -4
- package/node_modules/@aws-sdk/client-ssm/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-ssm/package.json +4 -4
- package/node_modules/@aws-sdk/core/dist-cjs/submodules/client/index.js +1 -2
- package/node_modules/@aws-sdk/core/dist-es/submodules/client/setFeature.js +0 -2
- package/node_modules/@aws-sdk/core/package.json +4 -5
- package/node_modules/@aws-sdk/credential-provider-env/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-http/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +10 -10
- package/node_modules/@aws-sdk/credential-provider-login/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-node/package.json +8 -8
- package/node_modules/@aws-sdk/credential-provider-process/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-sdk-s3/package.json +3 -3
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/package.json +3 -3
- package/node_modules/@aws-sdk/token-providers/package.json +4 -4
- package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.browser.js +8 -8
- package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.js +8 -8
- package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/StandardRetryStrategy.js +2 -2
- package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/retries-2026-config.js +6 -6
- package/node_modules/@smithy/core/dist-types/submodules/retry/util-retry/retries-2026-config.d.ts +16 -6
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/retry/util-retry/retries-2026-config.d.ts +16 -6
- package/node_modules/@smithy/core/package.json +1 -1
- package/node_modules/mailparser/CHANGELOG.md +7 -0
- package/node_modules/mailparser/package.json +3 -3
- package/node_modules/nodemailer/CHANGELOG.md +28 -0
- package/node_modules/nodemailer/README.md +21 -0
- package/node_modules/nodemailer/dist/cjs/addressparser/index.js +185 -2
- package/node_modules/nodemailer/dist/cjs/dkim/sign.js +2 -2
- package/node_modules/nodemailer/dist/cjs/errors.d.ts +2 -0
- package/node_modules/nodemailer/dist/cjs/errors.js +11 -1
- package/node_modules/nodemailer/dist/cjs/json-transport/index.js +2 -0
- package/node_modules/nodemailer/dist/cjs/mailer/index.d.ts +12 -2
- package/node_modules/nodemailer/dist/cjs/mailer/index.js +56 -4
- package/node_modules/nodemailer/dist/cjs/mailer/mail-message.d.ts +10 -0
- package/node_modules/nodemailer/dist/cjs/mime-funcs/index.d.ts +2 -1
- package/node_modules/nodemailer/dist/cjs/mime-funcs/index.js +72 -2
- package/node_modules/nodemailer/dist/cjs/mime-node/index.js +1 -73
- package/node_modules/nodemailer/dist/cjs/package-info.d.ts +1 -1
- package/node_modules/nodemailer/dist/cjs/package-info.js +1 -1
- package/node_modules/nodemailer/dist/cjs/shared/index.d.ts +23 -0
- package/node_modules/nodemailer/dist/cjs/shared/index.js +79 -0
- package/node_modules/nodemailer/dist/cjs/smtp-connection/index.js +6 -0
- package/node_modules/nodemailer/dist/cjs/smtp-pool/index.d.ts +10 -3
- package/node_modules/nodemailer/dist/cjs/smtp-pool/index.js +70 -12
- package/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.js +26 -4
- package/node_modules/nodemailer/dist/cjs/smtp-transport/index.d.ts +1 -0
- package/node_modules/nodemailer/dist/cjs/smtp-transport/index.js +47 -35
- package/node_modules/nodemailer/dist/cjs/well-known/services.js +7 -0
- package/node_modules/nodemailer/dist/esm/addressparser/index.js +185 -2
- package/node_modules/nodemailer/dist/esm/dkim/sign.js +2 -2
- package/node_modules/nodemailer/dist/esm/errors.d.ts +2 -0
- package/node_modules/nodemailer/dist/esm/errors.js +9 -0
- package/node_modules/nodemailer/dist/esm/json-transport/index.js +2 -0
- package/node_modules/nodemailer/dist/esm/mailer/index.d.ts +12 -2
- package/node_modules/nodemailer/dist/esm/mailer/index.js +56 -4
- package/node_modules/nodemailer/dist/esm/mailer/mail-message.d.ts +10 -0
- package/node_modules/nodemailer/dist/esm/mime-funcs/index.d.ts +2 -1
- package/node_modules/nodemailer/dist/esm/mime-funcs/index.js +72 -2
- package/node_modules/nodemailer/dist/esm/mime-node/index.js +1 -73
- package/node_modules/nodemailer/dist/esm/package-info.d.ts +1 -1
- package/node_modules/nodemailer/dist/esm/package-info.js +1 -1
- package/node_modules/nodemailer/dist/esm/shared/index.d.ts +23 -0
- package/node_modules/nodemailer/dist/esm/shared/index.js +78 -0
- package/node_modules/nodemailer/dist/esm/smtp-connection/index.js +6 -0
- package/node_modules/nodemailer/dist/esm/smtp-pool/index.d.ts +10 -3
- package/node_modules/nodemailer/dist/esm/smtp-pool/index.js +70 -12
- package/node_modules/nodemailer/dist/esm/smtp-pool/pool-resource.js +26 -4
- package/node_modules/nodemailer/dist/esm/smtp-transport/index.d.ts +1 -0
- package/node_modules/nodemailer/dist/esm/smtp-transport/index.js +47 -35
- package/node_modules/nodemailer/dist/esm/well-known/services.js +7 -0
- package/node_modules/nodemailer/dist/well-known/services.json +8 -0
- package/node_modules/nodemailer/package.json +7 -7
- package/package.json +7 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as shared from '../shared/index.js';
|
|
2
2
|
import * as mimeFuncs from '../mime-funcs/index.js';
|
|
3
3
|
import crypto from 'node:crypto';
|
|
4
4
|
import * as errors from '../errors.js';
|
|
@@ -65,7 +65,7 @@ function generateDKIMHeader(domainName, keySelector, fieldNames, hashAlgo, bodyH
|
|
|
65
65
|
'v=1',
|
|
66
66
|
'a=rsa-' + hashAlgo,
|
|
67
67
|
'c=relaxed/relaxed',
|
|
68
|
-
'd=' +
|
|
68
|
+
'd=' + shared.normalizeDomain(cleanTagValue(domainName), false),
|
|
69
69
|
'q=dns/txt',
|
|
70
70
|
's=' + cleanTagValue(keySelector),
|
|
71
71
|
'bh=' + bodyHash,
|
|
@@ -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";
|
|
@@ -26,6 +26,7 @@ export const ERROR_CODES = {
|
|
|
26
26
|
EMESSAGE: 'Message delivery error',
|
|
27
27
|
EOTP: 'Invalid one-time passcode data (otp option)',
|
|
28
28
|
ESTREAM: 'Stream processing error',
|
|
29
|
+
EABORT: 'Message sending aborted',
|
|
29
30
|
// Authentication errors
|
|
30
31
|
EAUTH: 'Authentication failed',
|
|
31
32
|
ENOAUTH: 'Authentication credentials not provided',
|
|
@@ -55,6 +56,7 @@ export const EENVELOPE = 'EENVELOPE';
|
|
|
55
56
|
export const EMESSAGE = 'EMESSAGE';
|
|
56
57
|
export const EOTP = 'EOTP';
|
|
57
58
|
export const ESTREAM = 'ESTREAM';
|
|
59
|
+
export const EABORT = 'EABORT';
|
|
58
60
|
export const EAUTH = 'EAUTH';
|
|
59
61
|
export const ENOAUTH = 'ENOAUTH';
|
|
60
62
|
export const EOAUTH2 = 'EOAUTH2';
|
|
@@ -67,6 +69,13 @@ export const EPROXY = 'EPROXY';
|
|
|
67
69
|
export const EFILEACCESS = 'EFILEACCESS';
|
|
68
70
|
export const EURLACCESS = 'EURLACCESS';
|
|
69
71
|
export const EFETCH = 'EFETCH';
|
|
72
|
+
/** Creates the error reported when a caller cancels an individual send. @internal */
|
|
73
|
+
export const createAbortError = (signal) => {
|
|
74
|
+
const err = new Error('Message sending aborted', { cause: signal.reason });
|
|
75
|
+
err.name = 'AbortError';
|
|
76
|
+
err.code = EABORT;
|
|
77
|
+
return err;
|
|
78
|
+
};
|
|
70
79
|
/**
|
|
71
80
|
* Tells whether the error ended the connection rather than rejected what was sent over it
|
|
72
81
|
*/
|
|
@@ -48,6 +48,8 @@ class JSONTransport {
|
|
|
48
48
|
}
|
|
49
49
|
delete data.envelope;
|
|
50
50
|
delete data.normalizedHeaders;
|
|
51
|
+
// the per-message AbortSignal is not message data
|
|
52
|
+
delete data.signal;
|
|
51
53
|
// the message field is the object itself with skipEncoding, the
|
|
52
54
|
// createTransport overload for that option types the result accordingly
|
|
53
55
|
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 */
|
|
@@ -176,8 +181,13 @@ declare class Mail<out T = SentMessageInfo, out D extends TransportOptions = Tra
|
|
|
176
181
|
dkim: DKIM | false;
|
|
177
182
|
transporter: Transport<T, D>;
|
|
178
183
|
logger: shared.Logger;
|
|
179
|
-
/**
|
|
180
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Closes the transport, the pooled SMTP transport closes its connections. With `force` the
|
|
186
|
+
* pooled transport also closes connections that are delivering a message
|
|
187
|
+
*/
|
|
188
|
+
close: (options?: {
|
|
189
|
+
force?: boolean;
|
|
190
|
+
}) => void;
|
|
181
191
|
/** Tells whether the transport can take a message right away */
|
|
182
192
|
isIdle: () => boolean;
|
|
183
193
|
/** Checks the configuration, the SMTP transports connect and authenticate for it */
|
|
@@ -18,6 +18,16 @@ import crypto from 'node:crypto';
|
|
|
18
18
|
* asks a server to accept 100, so a real send is bounded far below this.
|
|
19
19
|
*/
|
|
20
20
|
const DEFAULT_MAX_RECIPIENTS = 100000;
|
|
21
|
+
/**
|
|
22
|
+
* Duck-typed so that signals from another realm or a polyfill are accepted as well
|
|
23
|
+
*/
|
|
24
|
+
function isAbortSignal(value) {
|
|
25
|
+
return (typeof value === 'object' &&
|
|
26
|
+
value !== null &&
|
|
27
|
+
'aborted' in value &&
|
|
28
|
+
typeof value.addEventListener === 'function' &&
|
|
29
|
+
typeof value.removeEventListener === 'function');
|
|
30
|
+
}
|
|
21
31
|
/**
|
|
22
32
|
* Creates an object for exposing the Mail API
|
|
23
33
|
*
|
|
@@ -119,11 +129,43 @@ class Mail extends EventEmitter {
|
|
|
119
129
|
this.getSocket = false;
|
|
120
130
|
}
|
|
121
131
|
const mail = new MailMessage(this, data);
|
|
132
|
+
const signalOption = mail.data.signal;
|
|
133
|
+
const signal = isAbortSignal(signalOption) ? signalOption : undefined;
|
|
134
|
+
let settled = false;
|
|
135
|
+
const removeAbortListener = () => signal?.removeEventListener('abort', onAbort);
|
|
136
|
+
const finish = (err, info) => {
|
|
137
|
+
if (settled) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
settled = true;
|
|
141
|
+
removeAbortListener();
|
|
142
|
+
if (err) {
|
|
143
|
+
mail.releaseStreams();
|
|
144
|
+
}
|
|
145
|
+
done(err, info);
|
|
146
|
+
};
|
|
122
147
|
// a failed message is not going to be read anymore, release its content streams
|
|
123
148
|
const fail = (err) => {
|
|
124
|
-
|
|
125
|
-
done(err);
|
|
149
|
+
finish(err);
|
|
126
150
|
};
|
|
151
|
+
function onAbort() {
|
|
152
|
+
fail(errors.createAbortError(signal));
|
|
153
|
+
}
|
|
154
|
+
if (signalOption !== undefined && signalOption !== null && !signal) {
|
|
155
|
+
const err = new Error('The signal option must be an AbortSignal');
|
|
156
|
+
err.code = errors.ECONFIG;
|
|
157
|
+
setImmediate(() => fail(err));
|
|
158
|
+
return promise;
|
|
159
|
+
}
|
|
160
|
+
// Mail handles a pre-aborted signal and cancellation during plugin processing for every
|
|
161
|
+
// transport; a transport without supportsAbortSignal ignores the signal once it is called
|
|
162
|
+
if (signal) {
|
|
163
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
164
|
+
if (signal.aborted) {
|
|
165
|
+
setImmediate(onAbort);
|
|
166
|
+
return promise;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
127
169
|
this.logger.debug({
|
|
128
170
|
tnx: 'transport',
|
|
129
171
|
name: this.transporter.name,
|
|
@@ -131,6 +173,9 @@ class Mail extends EventEmitter {
|
|
|
131
173
|
action: 'send'
|
|
132
174
|
}, 'Sending mail using %s/%s', this.transporter.name, this.transporter.version);
|
|
133
175
|
this._processPlugins('compile', mail, err => {
|
|
176
|
+
if (settled) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
134
179
|
if (err) {
|
|
135
180
|
this.logger.error({
|
|
136
181
|
err,
|
|
@@ -168,6 +213,9 @@ class Mail extends EventEmitter {
|
|
|
168
213
|
return fail(err);
|
|
169
214
|
}
|
|
170
215
|
this._processPlugins('stream', mail, err => {
|
|
216
|
+
if (settled) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
171
219
|
if (err) {
|
|
172
220
|
this.logger.error({
|
|
173
221
|
err,
|
|
@@ -187,16 +235,17 @@ class Mail extends EventEmitter {
|
|
|
187
235
|
return dkim.sign(input, mail.data._dkim);
|
|
188
236
|
});
|
|
189
237
|
}
|
|
238
|
+
// The transport takes ownership of cancellation from here, including queued work.
|
|
239
|
+
removeAbortListener();
|
|
190
240
|
this.transporter.send(mail, (...args) => {
|
|
191
241
|
if (args[0]) {
|
|
192
|
-
mail.releaseStreams();
|
|
193
242
|
this.logger.error({
|
|
194
243
|
err: args[0],
|
|
195
244
|
tnx: 'transport',
|
|
196
245
|
action: 'send'
|
|
197
246
|
}, 'Send Error: %s', args[0].message);
|
|
198
247
|
}
|
|
199
|
-
|
|
248
|
+
finish(...args);
|
|
200
249
|
});
|
|
201
250
|
});
|
|
202
251
|
});
|
|
@@ -226,6 +275,9 @@ class Mail extends EventEmitter {
|
|
|
226
275
|
let pos = 0;
|
|
227
276
|
let block = 'default';
|
|
228
277
|
const processPlugins = () => {
|
|
278
|
+
if (mail.data.signal?.aborted) {
|
|
279
|
+
return callback(errors.createAbortError(mail.data.signal));
|
|
280
|
+
}
|
|
229
281
|
let curplugins = block === 'default' ? defaultPlugins : userPlugins;
|
|
230
282
|
if (pos >= curplugins.length) {
|
|
231
283
|
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
|
|
@@ -132,8 +132,75 @@ export function encodeWord(data, mimeWordEncoding, maxLength) {
|
|
|
132
132
|
}
|
|
133
133
|
return '=?' + toCharset + '?' + mimeWordEncoding + '?' + encodedStr + (encodedStr.substr(-2) === '?=' ? '' : '?=');
|
|
134
134
|
}
|
|
135
|
+
// An encoded-word as RFC 2047 section 2 spells it: a charset token (with an optional RFC 2231
|
|
136
|
+
// language), B or Q, and encoded text without '?' or whitespace. None of the parts can hold the
|
|
137
|
+
// '?' that separates them, so the pattern never backtracks
|
|
138
|
+
const VALID_ENCODED_WORD = /^=\?[^\s()<>@,;:"/[\]?.=]+\?[BbQq]\?[^?\s]+\?=$/;
|
|
139
|
+
// What a lenient decoder reads as an encoded-word: libmime and Python decode
|
|
140
|
+
// '=?utf-8?Q?a b?=' across the space as well. Applied sticky at a '=?', and every part stops
|
|
141
|
+
// at the next '?', so it does not backtrack either
|
|
142
|
+
const LENIENT_ENCODED_WORD = /[=]\?[^?]*\?[BbQq]\?[^?]*\?=/y;
|
|
135
143
|
/**
|
|
136
|
-
*
|
|
144
|
+
* Marks the text a receiver would read as an encoded-word when it is not one valid encoded-word
|
|
145
|
+
* on its own. RFC 2047 section 7 requires that a word beginning with '=?' and ending with '?='
|
|
146
|
+
* is a valid encoded-word, and decoders also decode a look-alike that spans whitespace, so
|
|
147
|
+
* '=?utf-8?X?x?=' and 'see =?utf-8?Q?a b?= here' read differently on every receiver. A valid
|
|
148
|
+
* encoded-word is left alone, which is what lets a caller pass a value that is already encoded,
|
|
149
|
+
* as most other mail libraries do.
|
|
150
|
+
*
|
|
151
|
+
* The bounds of the word around each '=?' are found once per word and reused, walking back to
|
|
152
|
+
* the start of a long word from every '=?' it holds would be quadratic.
|
|
153
|
+
*
|
|
154
|
+
* @param value String to look in
|
|
155
|
+
* @param range The first and the last offset that needs encoding so far, -1 for none
|
|
156
|
+
* @return The range, widened to cover the words of every invalid look-alike
|
|
157
|
+
*/
|
|
158
|
+
function _markInvalidEncodedWords(value, range) {
|
|
159
|
+
const len = value.length;
|
|
160
|
+
const isSpace = (pos) => /\s/.test(value.charAt(pos));
|
|
161
|
+
// the word last looked at, its start and the offset just past it
|
|
162
|
+
let wordStart = 0;
|
|
163
|
+
let wordEnd = -1;
|
|
164
|
+
const wordAt = (pos) => {
|
|
165
|
+
if (pos < wordEnd) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
// the previous word ended at whitespace, so the walk back stops before reaching it
|
|
169
|
+
wordStart = pos;
|
|
170
|
+
while (wordStart > 0 && !isSpace(wordStart - 1)) {
|
|
171
|
+
wordStart--;
|
|
172
|
+
}
|
|
173
|
+
wordEnd = pos;
|
|
174
|
+
while (wordEnd < len && !isSpace(wordEnd)) {
|
|
175
|
+
wordEnd++;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
let pos = value.indexOf('=?');
|
|
179
|
+
while (pos >= 0) {
|
|
180
|
+
wordAt(pos);
|
|
181
|
+
const start = wordStart;
|
|
182
|
+
LENIENT_ENCODED_WORD.lastIndex = pos;
|
|
183
|
+
const match = LENIENT_ENCODED_WORD.exec(value);
|
|
184
|
+
const end = match ? pos + match[0].length : wordEnd;
|
|
185
|
+
if (match && end > wordEnd) {
|
|
186
|
+
// the look-alike runs across whitespace, on to the word it ends in
|
|
187
|
+
wordAt(end - 1);
|
|
188
|
+
}
|
|
189
|
+
const word = value.substring(start, wordEnd);
|
|
190
|
+
// without a match, a word that begins with '=?' and ends with '?=' is still invalid
|
|
191
|
+
const looksLike = match ? true : start === pos && word.length >= 4 && word.endsWith('?=');
|
|
192
|
+
const valid = start === pos && wordEnd === end && word.length <= 75 && VALID_ENCODED_WORD.test(word);
|
|
193
|
+
if (looksLike && !valid) {
|
|
194
|
+
range[0] = range[0] < 0 ? start : Math.min(range[0], start);
|
|
195
|
+
range[1] = Math.max(range[1], wordEnd - 1);
|
|
196
|
+
}
|
|
197
|
+
pos = value.indexOf('=?', match ? end : pos + 2);
|
|
198
|
+
}
|
|
199
|
+
return range;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Finds word sequences with non ascii text, and words that look like an invalid encoded-word,
|
|
203
|
+
* and converts these to mime words. A valid encoded-word is passed through as it is.
|
|
137
204
|
*
|
|
138
205
|
* @param value String to be encoded
|
|
139
206
|
* @param mimeWordEncoding='Q' Encoding for the mime word, either Q or B
|
|
@@ -157,11 +224,14 @@ export function encodeWords(value, mimeWordEncoding, maxLength, encodeAll) {
|
|
|
157
224
|
lastSpecial = i;
|
|
158
225
|
}
|
|
159
226
|
}
|
|
227
|
+
if (value.indexOf('=?') >= 0) {
|
|
228
|
+
[firstSpecial, lastSpecial] = _markInvalidEncodedWords(value, [firstSpecial, lastSpecial]);
|
|
229
|
+
}
|
|
160
230
|
if (firstSpecial < 0) {
|
|
161
231
|
return value;
|
|
162
232
|
}
|
|
163
233
|
if (encodeAll) {
|
|
164
|
-
//
|
|
234
|
+
// the value needs encoding and it is requested to encode everything
|
|
165
235
|
return encodeWord(value, mimeWordEncoding, maxLength);
|
|
166
236
|
}
|
|
167
237
|
// encode from the start of the word holding the first such character to the end of the
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/* eslint no-undefined: 0, prefer-spread: 0, no-control-regex: 0 */
|
|
2
2
|
import crypto from 'node:crypto';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
|
-
import * as punycode from '../punycode/index.js';
|
|
5
4
|
import { PassThrough, finished, pipeline } from 'node:stream';
|
|
6
5
|
import * as shared from '../shared/index.js';
|
|
7
|
-
import urlModule from 'node:url';
|
|
8
6
|
import * as mimeFuncs from '../mime-funcs/index.js';
|
|
9
7
|
import * as qp from '../qp/index.js';
|
|
10
8
|
import * as base64 from '../base64/index.js';
|
|
@@ -55,20 +53,6 @@ function stripWhitespaceInAngleBrackets(value) {
|
|
|
55
53
|
}
|
|
56
54
|
return result + value.slice(pos);
|
|
57
55
|
}
|
|
58
|
-
// domainToASCII and domainToUnicode are WHATWG host parsers rather than plain IDNA
|
|
59
|
-
// mappers, so they do more than map: they cut the host at '/', '\\', '?' and '#', drop C0
|
|
60
|
-
// controls, and percent-decode. Handing them 'evil.example/mail.corp.example' returns the
|
|
61
|
-
// deliverable 'evil.example', which would turn a value the bundled codec leaves as
|
|
62
|
-
// unroutable garbage into mail for a domain the sender never named. None of these
|
|
63
|
-
// characters are legal in a domain, so keep them away from the mapper.
|
|
64
|
-
const URL_PARSER_UNSAFE = /[/\\?#%\x00-\x20\x7F]/;
|
|
65
|
-
// RFC 1035 bounds a label at 63 octets and a domain at 253. An A-label is never shorter than
|
|
66
|
-
// the code points it encodes, so anything past these bounds could not have become a valid
|
|
67
|
-
// domain whichever way it is encoded. The bundled codec is super-linear in the length of a
|
|
68
|
-
// label, a 60 KB label of distinct code points took seconds to encode, several times per
|
|
69
|
-
// address, so it is only handed what could be a domain
|
|
70
|
-
const MAX_DOMAIN_LENGTH = 253;
|
|
71
|
-
const MAX_LABEL_LENGTH = 63;
|
|
72
56
|
// pipeline() needs a callback to not throw, the errors it sees reach the last stream anyway
|
|
73
57
|
const PIPELINE_NOOP = () => false;
|
|
74
58
|
// The error a node streaming into an output that was destroyed stops with
|
|
@@ -77,62 +61,6 @@ function abortedError() {
|
|
|
77
61
|
err.code = errors.ESTREAM;
|
|
78
62
|
return err;
|
|
79
63
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Checks a domain against the DNS length limits, counted in code points per label and in
|
|
82
|
-
* total. The label separators are the ones the bundled codec splits on.
|
|
83
|
-
*
|
|
84
|
-
* @param domain Domain to check
|
|
85
|
-
* @return true if a label or the domain as a whole is too long to be a valid domain
|
|
86
|
-
*/
|
|
87
|
-
function exceedsDomainLimits(domain) {
|
|
88
|
-
let total = 0;
|
|
89
|
-
let label = 0;
|
|
90
|
-
for (const char of domain) {
|
|
91
|
-
total++;
|
|
92
|
-
if (char === '.' || char === '。' || char === '.' || char === '。') {
|
|
93
|
-
label = 0;
|
|
94
|
-
}
|
|
95
|
-
else if (++label > MAX_LABEL_LENGTH) {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return total > MAX_DOMAIN_LENGTH;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Encodes a domain the way browsers, the WHATWG URL Standard and DNS facing resolvers do,
|
|
103
|
-
* which is with UTS-46 mapping applied before the Punycode step.
|
|
104
|
-
*
|
|
105
|
-
* The bundled codec is plain RFC 3492 and maps nothing, so it disagrees with every
|
|
106
|
-
* conformant parser on any domain holding a mapped or ignored code point. An invisible
|
|
107
|
-
* U+00AD in 'compa\u00ADny.com' encoded to 'xn--company-pka.com' where a validator reads
|
|
108
|
-
* 'company.com', which let an allow-listed domain be checked and a different one mailed.
|
|
109
|
-
*
|
|
110
|
-
* Anything the URL parser does not accept as a hostname, an address literal such as
|
|
111
|
-
* '[127.0.0.1]' included, comes back empty and falls through to the bundled codec, which
|
|
112
|
-
* leaves those as they were supplied.
|
|
113
|
-
*
|
|
114
|
-
* @param domain Domain to encode, already lowercased by the caller
|
|
115
|
-
* @param toUnicode Return the U-label form instead of the A-label form
|
|
116
|
-
* @return Encoded domain
|
|
117
|
-
*/
|
|
118
|
-
function normalizeDomain(domain, toUnicode) {
|
|
119
|
-
// domainToASCII and domainToUnicode landed in Node 7, the bundled codec covers Node 6
|
|
120
|
-
if (typeof urlModule.domainToASCII === 'function' && typeof urlModule.domainToUnicode === 'function' && !URL_PARSER_UNSAFE.test(domain)) {
|
|
121
|
-
// The U-label form is decoded from the A-label form rather than from the input:
|
|
122
|
-
// Deno's domainToASCII returns an empty string for a label it cannot decode, while
|
|
123
|
-
// its domainToUnicode returns the label with U+FFFD in place of the bad part
|
|
124
|
-
const ascii = urlModule.domainToASCII(domain);
|
|
125
|
-
const mapped = ascii && toUnicode ? urlModule.domainToUnicode(ascii) : ascii;
|
|
126
|
-
if (mapped) {
|
|
127
|
-
return mapped;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (exceedsDomainLimits(domain)) {
|
|
131
|
-
// too long to be a domain whichever way it is encoded, keep it as supplied
|
|
132
|
-
return domain;
|
|
133
|
-
}
|
|
134
|
-
return toUnicode ? punycode.toUnicode(domain) : punycode.toASCII(domain);
|
|
135
|
-
}
|
|
136
64
|
/**
|
|
137
65
|
* Removes the characters that must never reach a multipart delimiter line.
|
|
138
66
|
*
|
|
@@ -1500,7 +1428,7 @@ class MimeNode {
|
|
|
1500
1428
|
// symmetry on both sides of the '@' rather than being encoded to an A-label
|
|
1501
1429
|
const smtputf8 = /[\x80-\uFFFF]/.test(user);
|
|
1502
1430
|
try {
|
|
1503
|
-
encodedDomain = normalizeDomain(domain
|
|
1431
|
+
encodedDomain = shared.normalizeDomain(domain, smtputf8);
|
|
1504
1432
|
}
|
|
1505
1433
|
catch (_err) {
|
|
1506
1434
|
// keep domain as supplied
|
|
@@ -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;
|
|
@@ -8,6 +8,8 @@ import { isProtoKey, copyOwnKeys } from './objects.js';
|
|
|
8
8
|
import dns from 'node:dns';
|
|
9
9
|
import net from 'node:net';
|
|
10
10
|
import os from 'node:os';
|
|
11
|
+
import urlModule from 'node:url';
|
|
12
|
+
import * as punycode from '../punycode/index.js';
|
|
11
13
|
import { finished } from 'node:stream';
|
|
12
14
|
// re-exported for the callers that already depend on this module, see ./objects
|
|
13
15
|
export { isProtoKey, copyOwnKeys };
|
|
@@ -717,3 +719,79 @@ function createDefaultLogger(levels) {
|
|
|
717
719
|
});
|
|
718
720
|
return logger;
|
|
719
721
|
}
|
|
722
|
+
// domainToASCII and domainToUnicode are WHATWG host parsers rather than plain IDNA
|
|
723
|
+
// mappers, so they do more than map: they cut the host at '/', '\\', '?' and '#', drop C0
|
|
724
|
+
// controls, and percent-decode. Handing them 'evil.example/mail.corp.example' returns the
|
|
725
|
+
// deliverable 'evil.example', which would turn a value the bundled codec leaves as
|
|
726
|
+
// unroutable garbage into mail for a domain the sender never named. None of these
|
|
727
|
+
// characters are legal in a domain, so keep them away from the mapper.
|
|
728
|
+
const URL_PARSER_UNSAFE = /[/\\?#%\x00-\x20\x7F]/;
|
|
729
|
+
// RFC 1035 bounds a label at 63 octets and a domain at 253. An A-label is never shorter than
|
|
730
|
+
// the code points it encodes, so anything past these bounds could not have become a valid
|
|
731
|
+
// domain whichever way it is encoded. The bundled codec is super-linear in the length of a
|
|
732
|
+
// label, a 60 KB label of distinct code points took seconds to encode, several times per
|
|
733
|
+
// address, so it is only handed what could be a domain
|
|
734
|
+
const MAX_DOMAIN_LENGTH = 253;
|
|
735
|
+
const MAX_LABEL_LENGTH = 63;
|
|
736
|
+
/**
|
|
737
|
+
* Checks a domain against the DNS length limits, counted in code points per label and in
|
|
738
|
+
* total. The label separators are the ones the bundled codec splits on.
|
|
739
|
+
*
|
|
740
|
+
* @param domain Domain to check
|
|
741
|
+
* @return true if a label or the domain as a whole is too long to be a valid domain
|
|
742
|
+
*/
|
|
743
|
+
function exceedsDomainLimits(domain) {
|
|
744
|
+
let total = 0;
|
|
745
|
+
let label = 0;
|
|
746
|
+
for (const char of domain) {
|
|
747
|
+
total++;
|
|
748
|
+
if (char === '.' || char === '。' || char === '.' || char === '。') {
|
|
749
|
+
label = 0;
|
|
750
|
+
}
|
|
751
|
+
else if (++label > MAX_LABEL_LENGTH) {
|
|
752
|
+
return true;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
return total > MAX_DOMAIN_LENGTH;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Encodes a domain the way browsers, the WHATWG URL Standard and DNS facing resolvers do,
|
|
759
|
+
* which is with UTS-46 mapping applied before the Punycode step.
|
|
760
|
+
*
|
|
761
|
+
* The bundled codec is plain RFC 3492 and maps nothing, so it disagrees with every
|
|
762
|
+
* conformant parser on any domain holding a mapped or ignored code point. An invisible
|
|
763
|
+
* U+00AD in 'compa\u00ADny.com' encoded to 'xn--company-pka.com' where a validator reads
|
|
764
|
+
* 'company.com', which let an allow-listed domain be checked and a different one mailed.
|
|
765
|
+
*
|
|
766
|
+
* Anything the URL parser does not accept as a hostname, an address literal such as
|
|
767
|
+
* '[127.0.0.1]' included, comes back empty and falls through to the bundled codec, which
|
|
768
|
+
* leaves those as they were supplied apart from lowercasing them.
|
|
769
|
+
*
|
|
770
|
+
* The mapper gets the domain as supplied, since UTS-46 does its own case mapping and
|
|
771
|
+
* toLowerCase() differs from it: it turns U+1E9E into U+00DF where Node 20 and 22 map it
|
|
772
|
+
* to 'ss', and a word-final U+03A3 into U+03C2 where UTS-46 gives U+03C3. Lowercasing
|
|
773
|
+
* first sent 'user@stra\u1E9Ee.de', which a validator reads as strasse.de, to xn--strae-oqa.de.
|
|
774
|
+
*
|
|
775
|
+
* @param domain Domain to encode
|
|
776
|
+
* @param toUnicode Return the U-label form instead of the A-label form
|
|
777
|
+
* @return Encoded domain
|
|
778
|
+
*/
|
|
779
|
+
export function normalizeDomain(domain, toUnicode) {
|
|
780
|
+
// domainToASCII and domainToUnicode landed in Node 7, the bundled codec covers Node 6
|
|
781
|
+
if (typeof urlModule.domainToASCII === 'function' && typeof urlModule.domainToUnicode === 'function' && !URL_PARSER_UNSAFE.test(domain)) {
|
|
782
|
+
// The U-label form is decoded from the A-label form rather than from the input:
|
|
783
|
+
// Deno's domainToASCII returns an empty string for a label it cannot decode, while
|
|
784
|
+
// its domainToUnicode returns the label with U+FFFD in place of the bad part
|
|
785
|
+
const ascii = urlModule.domainToASCII(domain);
|
|
786
|
+
const mapped = ascii && toUnicode ? urlModule.domainToUnicode(ascii) : ascii;
|
|
787
|
+
if (mapped) {
|
|
788
|
+
return mapped;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
domain = domain.toLowerCase();
|
|
792
|
+
if (exceedsDomainLimits(domain)) {
|
|
793
|
+
// too long to be a domain whichever way it is encoded, keep it as supplied
|
|
794
|
+
return domain;
|
|
795
|
+
}
|
|
796
|
+
return toUnicode ? punycode.toUnicode(domain) : punycode.toASCII(domain);
|
|
797
|
+
}
|
|
@@ -249,6 +249,9 @@ class SMTPConnection extends EventEmitter {
|
|
|
249
249
|
// socket object is set up but not yet connected
|
|
250
250
|
this._socket = this.options.socket;
|
|
251
251
|
return this._resolveAndConnect(opts, _resolved => {
|
|
252
|
+
if (this._destroyed || this._closing) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
252
255
|
try {
|
|
253
256
|
this._socket.connect(this.port, this.host, () => {
|
|
254
257
|
// a `secure` connection over a caller-provided socket must still
|
|
@@ -1039,6 +1042,9 @@ class SMTPConnection extends EventEmitter {
|
|
|
1039
1042
|
* @internal
|
|
1040
1043
|
*/
|
|
1041
1044
|
_upgradeConnection(callback) {
|
|
1045
|
+
if (this._destroyed || this._closing) {
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1042
1048
|
// RFC 3207 section 6: the client MUST discard any knowledge obtained from
|
|
1043
1049
|
// the server that was not received over the TLS-protected session. Drop any
|
|
1044
1050
|
// buffered input received before the handshake so a man-in-the-middle cannot
|
|
@@ -76,6 +76,7 @@ export interface SMTPPoolRateLimit {
|
|
|
76
76
|
* @param options SMTP Connection options
|
|
77
77
|
*/
|
|
78
78
|
declare class SMTPPool extends EventEmitter {
|
|
79
|
+
readonly supportsAbortSignal = true;
|
|
79
80
|
options: SMTPPoolResolvedOptions;
|
|
80
81
|
logger: shared.Logger;
|
|
81
82
|
name: string;
|
|
@@ -102,10 +103,16 @@ declare class SMTPPool extends EventEmitter {
|
|
|
102
103
|
*/
|
|
103
104
|
send(mail: MailMessage<SMTPPoolSentMessageInfo>, callback: SMTPPoolSendCallback): boolean;
|
|
104
105
|
/**
|
|
105
|
-
* Closes
|
|
106
|
-
* is closed
|
|
106
|
+
* Closes the pool. Idle connections are closed at once and a connection in the middle of a
|
|
107
|
+
* delivery finishes it first, unless `force` is set: then it is closed too and its message
|
|
108
|
+
* fails. `force` is for a caller that has given up on a delivery, such as one a server is
|
|
109
|
+
* stalling by trickling its replies, which no socket timeout notices.
|
|
110
|
+
*
|
|
111
|
+
* @param options.force - Also close connections that are delivering a message
|
|
107
112
|
*/
|
|
108
|
-
close(
|
|
113
|
+
close(options?: {
|
|
114
|
+
force?: boolean;
|
|
115
|
+
}): void;
|
|
109
116
|
/**
|
|
110
117
|
* Returns true if there are free slots in the queue
|
|
111
118
|
*/
|