@mavogel/awscdk-rootmail 0.1.42 → 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.
Files changed (91) hide show
  1. package/.jsii +8 -8
  2. package/lib/rootmail.js +1 -1
  3. package/lib/ses-receive.js +1 -1
  4. package/node_modules/@aws-sdk/checksums/package.json +3 -3
  5. package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-cjs/index.js +1 -1
  6. package/node_modules/@aws-sdk/client-cloudwatch-logs/package.json +4 -4
  7. package/node_modules/@aws-sdk/client-route-53/dist-cjs/index.js +1 -1
  8. package/node_modules/@aws-sdk/client-route-53/package.json +4 -4
  9. package/node_modules/@aws-sdk/client-s3/dist-cjs/index.js +1 -1
  10. package/node_modules/@aws-sdk/client-s3/package.json +7 -7
  11. package/node_modules/@aws-sdk/client-ses/dist-cjs/index.js +1 -1
  12. package/node_modules/@aws-sdk/client-ses/package.json +4 -4
  13. package/node_modules/@aws-sdk/client-ssm/dist-cjs/index.js +1 -1
  14. package/node_modules/@aws-sdk/client-ssm/package.json +4 -4
  15. package/node_modules/@aws-sdk/core/dist-cjs/submodules/client/index.js +1 -2
  16. package/node_modules/@aws-sdk/core/dist-es/submodules/client/setFeature.js +0 -2
  17. package/node_modules/@aws-sdk/core/package.json +4 -5
  18. package/node_modules/@aws-sdk/credential-provider-env/package.json +3 -3
  19. package/node_modules/@aws-sdk/credential-provider-http/package.json +3 -3
  20. package/node_modules/@aws-sdk/credential-provider-ini/package.json +10 -10
  21. package/node_modules/@aws-sdk/credential-provider-login/package.json +4 -4
  22. package/node_modules/@aws-sdk/credential-provider-node/package.json +8 -8
  23. package/node_modules/@aws-sdk/credential-provider-process/package.json +3 -3
  24. package/node_modules/@aws-sdk/credential-provider-sso/package.json +5 -5
  25. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +4 -4
  26. package/node_modules/@aws-sdk/middleware-sdk-s3/package.json +3 -3
  27. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
  28. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
  29. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
  30. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
  31. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
  32. package/node_modules/@aws-sdk/nested-clients/package.json +3 -3
  33. package/node_modules/@aws-sdk/token-providers/package.json +4 -4
  34. package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.browser.js +8 -8
  35. package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.js +8 -8
  36. package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/StandardRetryStrategy.js +2 -2
  37. package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/retries-2026-config.js +6 -6
  38. package/node_modules/@smithy/core/dist-types/submodules/retry/util-retry/retries-2026-config.d.ts +16 -6
  39. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/retry/util-retry/retries-2026-config.d.ts +16 -6
  40. package/node_modules/@smithy/core/package.json +1 -1
  41. package/node_modules/mailparser/CHANGELOG.md +7 -0
  42. package/node_modules/mailparser/package.json +3 -3
  43. package/node_modules/nodemailer/CHANGELOG.md +28 -0
  44. package/node_modules/nodemailer/README.md +21 -0
  45. package/node_modules/nodemailer/dist/cjs/addressparser/index.js +185 -2
  46. package/node_modules/nodemailer/dist/cjs/dkim/sign.js +2 -2
  47. package/node_modules/nodemailer/dist/cjs/errors.d.ts +2 -0
  48. package/node_modules/nodemailer/dist/cjs/errors.js +11 -1
  49. package/node_modules/nodemailer/dist/cjs/json-transport/index.js +2 -0
  50. package/node_modules/nodemailer/dist/cjs/mailer/index.d.ts +12 -2
  51. package/node_modules/nodemailer/dist/cjs/mailer/index.js +56 -4
  52. package/node_modules/nodemailer/dist/cjs/mailer/mail-message.d.ts +10 -0
  53. package/node_modules/nodemailer/dist/cjs/mime-funcs/index.d.ts +2 -1
  54. package/node_modules/nodemailer/dist/cjs/mime-funcs/index.js +72 -2
  55. package/node_modules/nodemailer/dist/cjs/mime-node/index.js +1 -73
  56. package/node_modules/nodemailer/dist/cjs/package-info.d.ts +1 -1
  57. package/node_modules/nodemailer/dist/cjs/package-info.js +1 -1
  58. package/node_modules/nodemailer/dist/cjs/shared/index.d.ts +23 -0
  59. package/node_modules/nodemailer/dist/cjs/shared/index.js +79 -0
  60. package/node_modules/nodemailer/dist/cjs/smtp-connection/index.js +6 -0
  61. package/node_modules/nodemailer/dist/cjs/smtp-pool/index.d.ts +10 -3
  62. package/node_modules/nodemailer/dist/cjs/smtp-pool/index.js +70 -12
  63. package/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.js +26 -4
  64. package/node_modules/nodemailer/dist/cjs/smtp-transport/index.d.ts +1 -0
  65. package/node_modules/nodemailer/dist/cjs/smtp-transport/index.js +47 -35
  66. package/node_modules/nodemailer/dist/cjs/well-known/services.js +7 -0
  67. package/node_modules/nodemailer/dist/esm/addressparser/index.js +185 -2
  68. package/node_modules/nodemailer/dist/esm/dkim/sign.js +2 -2
  69. package/node_modules/nodemailer/dist/esm/errors.d.ts +2 -0
  70. package/node_modules/nodemailer/dist/esm/errors.js +9 -0
  71. package/node_modules/nodemailer/dist/esm/json-transport/index.js +2 -0
  72. package/node_modules/nodemailer/dist/esm/mailer/index.d.ts +12 -2
  73. package/node_modules/nodemailer/dist/esm/mailer/index.js +56 -4
  74. package/node_modules/nodemailer/dist/esm/mailer/mail-message.d.ts +10 -0
  75. package/node_modules/nodemailer/dist/esm/mime-funcs/index.d.ts +2 -1
  76. package/node_modules/nodemailer/dist/esm/mime-funcs/index.js +72 -2
  77. package/node_modules/nodemailer/dist/esm/mime-node/index.js +1 -73
  78. package/node_modules/nodemailer/dist/esm/package-info.d.ts +1 -1
  79. package/node_modules/nodemailer/dist/esm/package-info.js +1 -1
  80. package/node_modules/nodemailer/dist/esm/shared/index.d.ts +23 -0
  81. package/node_modules/nodemailer/dist/esm/shared/index.js +78 -0
  82. package/node_modules/nodemailer/dist/esm/smtp-connection/index.js +6 -0
  83. package/node_modules/nodemailer/dist/esm/smtp-pool/index.d.ts +10 -3
  84. package/node_modules/nodemailer/dist/esm/smtp-pool/index.js +70 -12
  85. package/node_modules/nodemailer/dist/esm/smtp-pool/pool-resource.js +26 -4
  86. package/node_modules/nodemailer/dist/esm/smtp-transport/index.d.ts +1 -0
  87. package/node_modules/nodemailer/dist/esm/smtp-transport/index.js +47 -35
  88. package/node_modules/nodemailer/dist/esm/well-known/services.js +7 -0
  89. package/node_modules/nodemailer/dist/well-known/services.json +8 -0
  90. package/node_modules/nodemailer/package.json +7 -7
  91. package/package.json +7 -7
@@ -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
- /** Closes the transport, the pooled SMTP transport closes its connections */
180
- close: () => void;
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 */
@@ -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
- mail.releaseStreams();
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
- done(...args);
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 converts these to mime words
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
- * Finds word sequences with non ascii text and converts these to mime words
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
- // if it is requested to encode everything or the string contains something that resebles encoded word, then encode everything
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.toLowerCase(), smtputf8);
1469
+ encodedDomain = shared.normalizeDomain(domain, smtputf8);
1542
1470
  }
1543
1471
  catch (_err) {
1544
1472
  // keep domain as supplied
@@ -1,3 +1,3 @@
1
1
  export declare const name = "nodemailer";
2
- export declare const version = "10.3.1";
2
+ export declare const version = "10.5.0";
3
3
  export declare const homepage = "https://nodemailer.com/";
@@ -3,5 +3,5 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.homepage = exports.version = exports.name = void 0;
5
5
  exports.name = 'nodemailer';
6
- exports.version = '10.3.1';
6
+ exports.version = '10.5.0';
7
7
  exports.homepage = 'https://nodemailer.com/';
@@ -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 all connections in the pool. If there is a message being sent, the connection
106
- * is closed later
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(): void;
113
+ close(options?: {
114
+ force?: boolean;
115
+ }): void;
109
116
  /**
110
117
  * Returns true if there are free slots in the queue
111
118
  */