@mavogel/awscdk-rootmail 0.1.41 → 0.1.43
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 +9 -9
- package/lib/rootmail.js +1 -1
- package/lib/ses-receive.js +1 -1
- package/node_modules/@aws-sdk/checksums/package.json +5 -5
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-cloudwatch-logs/package.json +8 -8
- package/node_modules/@aws-sdk/client-route-53/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-route-53/package.json +9 -9
- package/node_modules/@aws-sdk/client-s3/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-s3/package.json +12 -12
- package/node_modules/@aws-sdk/client-ses/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-ses/package.json +8 -8
- package/node_modules/@aws-sdk/client-ssm/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-ssm/package.json +8 -8
- package/node_modules/@aws-sdk/core/dist-cjs/submodules/client/index.js +7 -2
- package/node_modules/@aws-sdk/core/dist-cjs/submodules/httpAuthSchemes/index.js +3 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/client/setFeature.js +0 -2
- package/node_modules/@aws-sdk/core/dist-es/submodules/client/util-endpoints/lib/aws/partitions.js +6 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.js +3 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/client/util-endpoints/lib/aws/partitions.d.ts +20 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.d.ts +1 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/util-endpoints/lib/aws/partitions.d.ts +20 -0
- package/node_modules/@aws-sdk/core/package.json +7 -8
- package/node_modules/@aws-sdk/credential-provider-env/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-http/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +12 -12
- package/node_modules/@aws-sdk/credential-provider-login/package.json +6 -6
- package/node_modules/@aws-sdk/credential-provider-node/package.json +10 -10
- package/node_modules/@aws-sdk/credential-provider-process/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +6 -6
- package/node_modules/@aws-sdk/middleware-sdk-route53/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-sdk-s3/package.json +6 -6
- 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 +8 -8
- package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +3 -3
- package/node_modules/@aws-sdk/token-providers/package.json +6 -6
- package/node_modules/@aws-sdk/types/package.json +2 -2
- package/node_modules/@aws-sdk/xml-builder/package.json +2 -2
- package/node_modules/@smithy/core/dist-cjs/submodules/client/index.js +1 -0
- package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.browser.js +41 -13
- package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.js +41 -13
- package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/command.js +1 -0
- package/node_modules/@smithy/core/dist-es/submodules/retry/middleware-retry/retryMiddleware.js +11 -5
- 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/race.js +22 -0
- 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/race.d.ts +3 -0
- 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/race.d.ts +3 -0
- 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 +2 -2
- package/node_modules/@smithy/fetch-http-handler/dist-cjs/index.js +10 -4
- package/node_modules/@smithy/fetch-http-handler/dist-es/fetch-http-handler.js +6 -2
- package/node_modules/@smithy/fetch-http-handler/dist-es/request-timeout.js +4 -2
- package/node_modules/@smithy/fetch-http-handler/dist-types/request-timeout.d.ts +12 -1
- package/node_modules/@smithy/fetch-http-handler/dist-types/ts3.4/request-timeout.d.ts +12 -1
- package/node_modules/@smithy/fetch-http-handler/package.json +3 -3
- package/node_modules/@smithy/node-http-handler/dist-cjs/index.js +31 -31
- package/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +2 -4
- package/node_modules/@smithy/node-http-handler/dist-es/set-socket-timeout.js +29 -27
- package/node_modules/@smithy/node-http-handler/dist-types/set-socket-timeout.d.ts +7 -3
- package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/set-socket-timeout.d.ts +7 -3
- package/node_modules/@smithy/node-http-handler/package.json +3 -3
- package/node_modules/@smithy/types/dist-types/middleware.d.ts +6 -0
- package/node_modules/@smithy/types/dist-types/ts3.4/middleware.d.ts +6 -0
- package/node_modules/@smithy/types/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 +10 -10
|
@@ -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,62 +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.
|
|
151
|
-
*
|
|
152
|
-
* @param domain Domain to encode, already lowercased by the caller
|
|
153
|
-
* @param toUnicode Return the U-label form instead of the A-label form
|
|
154
|
-
* @return Encoded domain
|
|
155
|
-
*/
|
|
156
|
-
function normalizeDomain(domain, toUnicode) {
|
|
157
|
-
// domainToASCII and domainToUnicode landed in Node 7, the bundled codec covers Node 6
|
|
158
|
-
if (typeof node_url_1.default.domainToASCII === 'function' && typeof node_url_1.default.domainToUnicode === 'function' && !URL_PARSER_UNSAFE.test(domain)) {
|
|
159
|
-
// The U-label form is decoded from the A-label form rather than from the input:
|
|
160
|
-
// Deno's domainToASCII returns an empty string for a label it cannot decode, while
|
|
161
|
-
// its domainToUnicode returns the label with U+FFFD in place of the bad part
|
|
162
|
-
const ascii = node_url_1.default.domainToASCII(domain);
|
|
163
|
-
const mapped = ascii && toUnicode ? node_url_1.default.domainToUnicode(ascii) : ascii;
|
|
164
|
-
if (mapped) {
|
|
165
|
-
return mapped;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (exceedsDomainLimits(domain)) {
|
|
169
|
-
// too long to be a domain whichever way it is encoded, keep it as supplied
|
|
170
|
-
return domain;
|
|
171
|
-
}
|
|
172
|
-
return toUnicode ? punycode.toUnicode(domain) : punycode.toASCII(domain);
|
|
173
|
-
}
|
|
174
102
|
/**
|
|
175
103
|
* Removes the characters that must never reach a multipart delimiter line.
|
|
176
104
|
*
|
|
@@ -1538,7 +1466,7 @@ class MimeNode {
|
|
|
1538
1466
|
// symmetry on both sides of the '@' rather than being encoded to an A-label
|
|
1539
1467
|
const smtputf8 = /[\x80-\uFFFF]/.test(user);
|
|
1540
1468
|
try {
|
|
1541
|
-
encodedDomain = normalizeDomain(domain
|
|
1469
|
+
encodedDomain = shared.normalizeDomain(domain, smtputf8);
|
|
1542
1470
|
}
|
|
1543
1471
|
catch (_err) {
|
|
1544
1472
|
// 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;
|
|
@@ -43,6 +43,7 @@ exports.recordStreamErrors = recordStreamErrors;
|
|
|
43
43
|
exports.destroyStream = destroyStream;
|
|
44
44
|
exports.unreadableStreamError = unreadableStreamError;
|
|
45
45
|
exports.resolveStream = resolveStream;
|
|
46
|
+
exports.normalizeDomain = normalizeDomain;
|
|
46
47
|
const urllib = __importStar(require("./url.js"));
|
|
47
48
|
const node_util_1 = __importDefault(require("node:util"));
|
|
48
49
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
@@ -54,6 +55,8 @@ Object.defineProperty(exports, "copyOwnKeys", { enumerable: true, get: function
|
|
|
54
55
|
const node_dns_1 = __importDefault(require("node:dns"));
|
|
55
56
|
const node_net_1 = __importDefault(require("node:net"));
|
|
56
57
|
const node_os_1 = __importDefault(require("node:os"));
|
|
58
|
+
const node_url_1 = __importDefault(require("node:url"));
|
|
59
|
+
const punycode = __importStar(require("../punycode/index.js"));
|
|
57
60
|
const node_stream_1 = require("node:stream");
|
|
58
61
|
const DNS_TTL = 5 * 60 * 1000;
|
|
59
62
|
const CACHE_CLEANUP_INTERVAL = 30 * 1000; // Minimum 30 seconds between cleanups
|
|
@@ -771,3 +774,79 @@ function createDefaultLogger(levels) {
|
|
|
771
774
|
});
|
|
772
775
|
return logger;
|
|
773
776
|
}
|
|
777
|
+
// domainToASCII and domainToUnicode are WHATWG host parsers rather than plain IDNA
|
|
778
|
+
// mappers, so they do more than map: they cut the host at '/', '\\', '?' and '#', drop C0
|
|
779
|
+
// controls, and percent-decode. Handing them 'evil.example/mail.corp.example' returns the
|
|
780
|
+
// deliverable 'evil.example', which would turn a value the bundled codec leaves as
|
|
781
|
+
// unroutable garbage into mail for a domain the sender never named. None of these
|
|
782
|
+
// characters are legal in a domain, so keep them away from the mapper.
|
|
783
|
+
const URL_PARSER_UNSAFE = /[/\\?#%\x00-\x20\x7F]/;
|
|
784
|
+
// RFC 1035 bounds a label at 63 octets and a domain at 253. An A-label is never shorter than
|
|
785
|
+
// the code points it encodes, so anything past these bounds could not have become a valid
|
|
786
|
+
// domain whichever way it is encoded. The bundled codec is super-linear in the length of a
|
|
787
|
+
// label, a 60 KB label of distinct code points took seconds to encode, several times per
|
|
788
|
+
// address, so it is only handed what could be a domain
|
|
789
|
+
const MAX_DOMAIN_LENGTH = 253;
|
|
790
|
+
const MAX_LABEL_LENGTH = 63;
|
|
791
|
+
/**
|
|
792
|
+
* Checks a domain against the DNS length limits, counted in code points per label and in
|
|
793
|
+
* total. The label separators are the ones the bundled codec splits on.
|
|
794
|
+
*
|
|
795
|
+
* @param domain Domain to check
|
|
796
|
+
* @return true if a label or the domain as a whole is too long to be a valid domain
|
|
797
|
+
*/
|
|
798
|
+
function exceedsDomainLimits(domain) {
|
|
799
|
+
let total = 0;
|
|
800
|
+
let label = 0;
|
|
801
|
+
for (const char of domain) {
|
|
802
|
+
total++;
|
|
803
|
+
if (char === '.' || char === '。' || char === '.' || char === '。') {
|
|
804
|
+
label = 0;
|
|
805
|
+
}
|
|
806
|
+
else if (++label > MAX_LABEL_LENGTH) {
|
|
807
|
+
return true;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return total > MAX_DOMAIN_LENGTH;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Encodes a domain the way browsers, the WHATWG URL Standard and DNS facing resolvers do,
|
|
814
|
+
* which is with UTS-46 mapping applied before the Punycode step.
|
|
815
|
+
*
|
|
816
|
+
* The bundled codec is plain RFC 3492 and maps nothing, so it disagrees with every
|
|
817
|
+
* conformant parser on any domain holding a mapped or ignored code point. An invisible
|
|
818
|
+
* U+00AD in 'compa\u00ADny.com' encoded to 'xn--company-pka.com' where a validator reads
|
|
819
|
+
* 'company.com', which let an allow-listed domain be checked and a different one mailed.
|
|
820
|
+
*
|
|
821
|
+
* Anything the URL parser does not accept as a hostname, an address literal such as
|
|
822
|
+
* '[127.0.0.1]' included, comes back empty and falls through to the bundled codec, which
|
|
823
|
+
* leaves those as they were supplied apart from lowercasing them.
|
|
824
|
+
*
|
|
825
|
+
* The mapper gets the domain as supplied, since UTS-46 does its own case mapping and
|
|
826
|
+
* toLowerCase() differs from it: it turns U+1E9E into U+00DF where Node 20 and 22 map it
|
|
827
|
+
* to 'ss', and a word-final U+03A3 into U+03C2 where UTS-46 gives U+03C3. Lowercasing
|
|
828
|
+
* first sent 'user@stra\u1E9Ee.de', which a validator reads as strasse.de, to xn--strae-oqa.de.
|
|
829
|
+
*
|
|
830
|
+
* @param domain Domain to encode
|
|
831
|
+
* @param toUnicode Return the U-label form instead of the A-label form
|
|
832
|
+
* @return Encoded domain
|
|
833
|
+
*/
|
|
834
|
+
function normalizeDomain(domain, toUnicode) {
|
|
835
|
+
// domainToASCII and domainToUnicode landed in Node 7, the bundled codec covers Node 6
|
|
836
|
+
if (typeof node_url_1.default.domainToASCII === 'function' && typeof node_url_1.default.domainToUnicode === 'function' && !URL_PARSER_UNSAFE.test(domain)) {
|
|
837
|
+
// The U-label form is decoded from the A-label form rather than from the input:
|
|
838
|
+
// Deno's domainToASCII returns an empty string for a label it cannot decode, while
|
|
839
|
+
// its domainToUnicode returns the label with U+FFFD in place of the bad part
|
|
840
|
+
const ascii = node_url_1.default.domainToASCII(domain);
|
|
841
|
+
const mapped = ascii && toUnicode ? node_url_1.default.domainToUnicode(ascii) : ascii;
|
|
842
|
+
if (mapped) {
|
|
843
|
+
return mapped;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
domain = domain.toLowerCase();
|
|
847
|
+
if (exceedsDomainLimits(domain)) {
|
|
848
|
+
// too long to be a domain whichever way it is encoded, keep it as supplied
|
|
849
|
+
return domain;
|
|
850
|
+
}
|
|
851
|
+
return toUnicode ? punycode.toUnicode(domain) : punycode.toASCII(domain);
|
|
852
|
+
}
|
|
@@ -287,6 +287,9 @@ class SMTPConnection extends node_events_1.EventEmitter {
|
|
|
287
287
|
// socket object is set up but not yet connected
|
|
288
288
|
this._socket = this.options.socket;
|
|
289
289
|
return this._resolveAndConnect(opts, _resolved => {
|
|
290
|
+
if (this._destroyed || this._closing) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
290
293
|
try {
|
|
291
294
|
this._socket.connect(this.port, this.host, () => {
|
|
292
295
|
// a `secure` connection over a caller-provided socket must still
|
|
@@ -1077,6 +1080,9 @@ class SMTPConnection extends node_events_1.EventEmitter {
|
|
|
1077
1080
|
* @internal
|
|
1078
1081
|
*/
|
|
1079
1082
|
_upgradeConnection(callback) {
|
|
1083
|
+
if (this._destroyed || this._closing) {
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1080
1086
|
// RFC 3207 section 6: the client MUST discard any knowledge obtained from
|
|
1081
1087
|
// the server that was not received over the TLS-protected session. Drop any
|
|
1082
1088
|
// 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
|
*/
|
|
@@ -56,6 +56,7 @@ const REQUEUE_MAX_DELAY = 2000;
|
|
|
56
56
|
class SMTPPool extends node_events_1.EventEmitter {
|
|
57
57
|
constructor(options) {
|
|
58
58
|
super();
|
|
59
|
+
this.supportsAbortSignal = true;
|
|
59
60
|
options = options || {};
|
|
60
61
|
if (typeof options === 'string') {
|
|
61
62
|
options = {
|
|
@@ -134,20 +135,33 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
134
135
|
return false;
|
|
135
136
|
}
|
|
136
137
|
// counted until the callback runs, whichever path runs it: delivered, failed, requeued
|
|
137
|
-
// until it gives up, or drained by close()
|
|
138
|
+
// until it gives up, aborted, or drained by close()
|
|
138
139
|
let counted = true;
|
|
140
|
+
let detachSignal;
|
|
139
141
|
this._pending++;
|
|
140
|
-
|
|
142
|
+
const entry = {
|
|
141
143
|
mail,
|
|
142
144
|
requeueAttempts: 0,
|
|
143
145
|
callback: (err, info) => {
|
|
144
|
-
if (counted) {
|
|
145
|
-
|
|
146
|
-
this._pending--;
|
|
146
|
+
if (!counted) {
|
|
147
|
+
return;
|
|
147
148
|
}
|
|
149
|
+
counted = false;
|
|
150
|
+
this._pending--;
|
|
151
|
+
detachSignal?.();
|
|
152
|
+
entry.resource = undefined;
|
|
148
153
|
callback(err, info);
|
|
149
154
|
}
|
|
150
|
-
}
|
|
155
|
+
};
|
|
156
|
+
this._queue.push(entry);
|
|
157
|
+
const signal = mail.data.signal;
|
|
158
|
+
if (signal) {
|
|
159
|
+
// one listener for the original entry, retained across connection-close retries
|
|
160
|
+
detachSignal = this._watchAbortSignal(entry, signal, () => counted);
|
|
161
|
+
if (signal.aborted) {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
151
165
|
if (this.idling && this._queue.length >= this.options.maxConnections) {
|
|
152
166
|
this.idling = false;
|
|
153
167
|
}
|
|
@@ -155,10 +169,49 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
155
169
|
return true;
|
|
156
170
|
}
|
|
157
171
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
172
|
+
* Fails a queued or assigned entry when its signal aborts: removes it from the queue, or
|
|
173
|
+
* closes the connection delivering it, so other deliveries in the pool can continue.
|
|
174
|
+
* Returns a function that removes the listener.
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
_watchAbortSignal(entry, signal, isPending) {
|
|
178
|
+
const onAbort = () => {
|
|
179
|
+
if (!isPending()) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const index = this._queue.indexOf(entry);
|
|
183
|
+
if (index !== -1) {
|
|
184
|
+
this._queue.splice(index, 1);
|
|
185
|
+
}
|
|
186
|
+
const resource = entry.resource;
|
|
187
|
+
if (resource && resource.queueEntry === entry) {
|
|
188
|
+
// Detach before closing: the close handler must not retry this message.
|
|
189
|
+
resource.queueEntry = false;
|
|
190
|
+
resource.close();
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
entry.callback(errors.createAbortError(signal));
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
// Removing a queued entry can make the pool idle again.
|
|
197
|
+
setImmediate(() => this._processMessages());
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
201
|
+
if (signal.aborted) {
|
|
202
|
+
setImmediate(onAbort);
|
|
203
|
+
}
|
|
204
|
+
return () => signal.removeEventListener('abort', onAbort);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Closes the pool. Idle connections are closed at once and a connection in the middle of a
|
|
208
|
+
* delivery finishes it first, unless `force` is set: then it is closed too and its message
|
|
209
|
+
* fails. `force` is for a caller that has given up on a delivery, such as one a server is
|
|
210
|
+
* stalling by trickling its replies, which no socket timeout notices.
|
|
211
|
+
*
|
|
212
|
+
* @param options.force - Also close connections that are delivering a message
|
|
160
213
|
*/
|
|
161
|
-
close() {
|
|
214
|
+
close(options) {
|
|
162
215
|
let connection;
|
|
163
216
|
const len = this._connections.length;
|
|
164
217
|
this._closed = true;
|
|
@@ -169,9 +222,10 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
169
222
|
if (!len && !this._queue.length) {
|
|
170
223
|
return;
|
|
171
224
|
}
|
|
172
|
-
// remove all available connections
|
|
225
|
+
// remove all available connections, and with `force` the busy ones too
|
|
226
|
+
const force = !!options?.force;
|
|
173
227
|
for (let i = len - 1; i >= 0; i--) {
|
|
174
|
-
if (this._connections[i] && this._connections[i].available) {
|
|
228
|
+
if (this._connections[i] && (force || this._connections[i].available)) {
|
|
175
229
|
connection = this._connections[i];
|
|
176
230
|
connection.close();
|
|
177
231
|
this.logger.info({
|
|
@@ -249,6 +303,7 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
249
303
|
this.emit('idle');
|
|
250
304
|
}
|
|
251
305
|
const entry = (connection.queueEntry = this._queue.shift());
|
|
306
|
+
entry.resource = connection;
|
|
252
307
|
entry.messageId = (connection.queueEntry.mail.message.getHeader('message-id') || '').replace(/[<>\s]/g, '');
|
|
253
308
|
connection.available = false;
|
|
254
309
|
this.logger.debug({
|
|
@@ -356,7 +411,9 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
356
411
|
setTimeout(() => {
|
|
357
412
|
let delay = 0;
|
|
358
413
|
if (connection.queueEntry) {
|
|
359
|
-
|
|
414
|
+
// a closed pool (a forced close ends a delivery on purpose) fails the
|
|
415
|
+
// message rather than queueing it for a retry that would never run
|
|
416
|
+
if (!this._closed && this._shouldRequeuOnConnectionClose(connection.queueEntry)) {
|
|
360
417
|
delay = this._requeueEntryOnConnectionClose(connection);
|
|
361
418
|
}
|
|
362
419
|
else {
|
|
@@ -418,6 +475,7 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
418
475
|
messageId: connection.queueEntry.messageId,
|
|
419
476
|
action: 'requeue'
|
|
420
477
|
}, 'Re-queued message <%s> for #%s. Attempt: #%s', connection.queueEntry.messageId, connection.id, connection.queueEntry.requeueAttempts);
|
|
478
|
+
connection.queueEntry.resource = undefined;
|
|
421
479
|
this._queue.unshift(connection.queueEntry);
|
|
422
480
|
connection.queueEntry = false;
|
|
423
481
|
return delay;
|