nodemailer 10.0.12 → 10.0.14

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 (49) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/addressparser/index.d.ts +0 -1
  3. package/dist/cjs/addressparser/index.js +152 -17
  4. package/dist/cjs/dkim/message-parser.js +28 -4
  5. package/dist/cjs/dkim/sign.d.ts +1 -0
  6. package/dist/cjs/dkim/sign.js +1 -0
  7. package/dist/cjs/mailer/index.d.ts +7 -1
  8. package/dist/cjs/mime-funcs/index.d.ts +2 -1
  9. package/dist/cjs/mime-funcs/index.js +197 -83
  10. package/dist/cjs/mime-node/index.js +2 -1
  11. package/dist/cjs/nodemailer.d.ts +13 -2
  12. package/dist/cjs/package-info.d.ts +1 -1
  13. package/dist/cjs/package-info.js +1 -1
  14. package/dist/cjs/punycode/index.js +1 -0
  15. package/dist/cjs/ses-transport/index.d.ts +6 -1
  16. package/dist/cjs/shared/index.d.ts +25 -1
  17. package/dist/cjs/shared/index.js +1 -0
  18. package/dist/cjs/smtp-connection/http-proxy-client.d.ts +11 -3
  19. package/dist/cjs/smtp-connection/http-proxy-client.js +17 -7
  20. package/dist/cjs/smtp-connection/index.d.ts +1 -1
  21. package/dist/cjs/smtp-connection/index.js +33 -15
  22. package/dist/cjs/smtp-pool/index.d.ts +6 -1
  23. package/dist/cjs/smtp-transport/index.d.ts +6 -1
  24. package/dist/cjs/well-known/services.js +6 -0
  25. package/dist/esm/addressparser/index.d.ts +0 -1
  26. package/dist/esm/addressparser/index.js +152 -17
  27. package/dist/esm/dkim/message-parser.js +28 -4
  28. package/dist/esm/dkim/sign.d.ts +1 -0
  29. package/dist/esm/dkim/sign.js +1 -0
  30. package/dist/esm/mailer/index.d.ts +7 -1
  31. package/dist/esm/mime-funcs/index.d.ts +2 -1
  32. package/dist/esm/mime-funcs/index.js +197 -83
  33. package/dist/esm/mime-node/index.js +2 -1
  34. package/dist/esm/nodemailer.d.ts +13 -2
  35. package/dist/esm/package-info.d.ts +1 -1
  36. package/dist/esm/package-info.js +1 -1
  37. package/dist/esm/punycode/index.js +1 -0
  38. package/dist/esm/ses-transport/index.d.ts +6 -1
  39. package/dist/esm/shared/index.d.ts +25 -1
  40. package/dist/esm/shared/index.js +1 -0
  41. package/dist/esm/smtp-connection/http-proxy-client.d.ts +11 -3
  42. package/dist/esm/smtp-connection/http-proxy-client.js +17 -7
  43. package/dist/esm/smtp-connection/index.d.ts +1 -1
  44. package/dist/esm/smtp-connection/index.js +33 -15
  45. package/dist/esm/smtp-pool/index.d.ts +6 -1
  46. package/dist/esm/smtp-transport/index.d.ts +6 -1
  47. package/dist/esm/well-known/services.js +6 -0
  48. package/dist/well-known/services.json +7 -0
  49. package/package.json +9 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## [10.0.14](https://github.com/nodemailer/nodemailer/compare/v10.0.13...v10.0.14) (2026-10-03)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **addressparser:** keep a quoted display name that holds no "@" out of the address ([3570d26](https://github.com/nodemailer/nodemailer/commit/3570d26c7b55f6e5df50d4076046600ad3fd040b))
9
+ * **addressparser:** keep the group recursion depth out of the options object ([a680254](https://github.com/nodemailer/nodemailer/commit/a68025405a1378c82e78f64ffad27b92c1035cbe))
10
+ * **addressparser:** stop a "[" from hiding the operators after it ([5619784](https://github.com/nodemailer/nodemailer/commit/561978491d5cc33d2052a6c89a499b838b960262))
11
+ * **dkim:** trim a header field name in linear time ([c6f7a55](https://github.com/nodemailer/nodemailer/commit/c6f7a55a2978bf031b8519ebf59baddf94c032c8))
12
+ * **mime-funcs:** read and write header parameters per rfc2045 and rfc2231 ([b8ccad7](https://github.com/nodemailer/nodemailer/commit/b8ccad723a7e49a674a4d70f32eb9fe77312008d))
13
+ * search only the new bytes for the end of the proxy CONNECT response ([81efd7b](https://github.com/nodemailer/nodemailer/commit/81efd7bfc559305f900d6a22b5c56aa94556002b))
14
+
15
+ ## [10.0.13](https://github.com/nodemailer/nodemailer/compare/v10.0.12...v10.0.13) (2026-09-30)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * read the advertised SASL methods without backtracking regexes ([b5a896f](https://github.com/nodemailer/nodemailer/commit/b5a896fcb02df1628329d7cd665ca08490b14b56))
21
+ * strip comments inside an angle-addr before it becomes the address ([a502247](https://github.com/nodemailer/nodemailer/commit/a502247555fd81773eac337486781f3b6008e16a))
22
+
3
23
  ## [10.0.12](https://github.com/nodemailer/nodemailer/compare/v10.0.11...v10.0.12) (2026-09-28)
4
24
 
5
25
 
@@ -39,7 +39,6 @@ export type Address = MailboxAddress | GroupAddress;
39
39
  *
40
40
  * @param str Address field
41
41
  * @param options Optional options object
42
- * @param options._depth Internal recursion depth counter (do not set manually)
43
42
  * @return An array of address objects
44
43
  */
45
44
  declare function addressparser(str: string | null | undefined, options: AddressParserOptions & {
@@ -242,6 +242,81 @@ function _recoverAddrSpec(data) {
242
242
  .filter(part => part)
243
243
  .join(' ');
244
244
  }
245
+ /**
246
+ * Takes the RFC 5322 comments out of the contents of an angle-addr.
247
+ *
248
+ * The tokenizer tracks a single open operator, so once '<' is open a '(' is plain text and
249
+ * a comment inside the brackets reached the address verbatim: 'Name <user@example.com(x)evil.com>'
250
+ * put 'user@example.com(x)evil.com' into the envelope, a value that is no mailbox and that a
251
+ * receiver stripping the comment reads as 'user@example.comevil.com' (GHSA-g73g-hqqh-jr95).
252
+ * A comment is folding whitespace, so it is read as a space that splits two atoms and as
253
+ * nothing next to an '@', the same rule the token walk applies outside the brackets. Quoted
254
+ * strings and domain literals are copied through untouched, a '(' in there is not a comment.
255
+ *
256
+ * @param address Contents of the angle brackets
257
+ * @return The address with the comments removed, and the text of the comments
258
+ */
259
+ function _stripAddressComments(address) {
260
+ const comments = [];
261
+ let result = '';
262
+ let comment = '';
263
+ let depth = 0;
264
+ let closer = '';
265
+ // carried along rather than read back off the growing result, which would flatten it on
266
+ // every comment (see lastChars in _handleAddress)
267
+ let lastChar = '';
268
+ for (let i = 0, len = address.length; i < len; i++) {
269
+ const chr = address.charAt(i);
270
+ if (depth) {
271
+ if (chr === '\\' && i < len - 1) {
272
+ comment += address.charAt(++i);
273
+ }
274
+ else if (chr === '(') {
275
+ depth++;
276
+ comment += chr;
277
+ }
278
+ else if (chr === ')' && !--depth) {
279
+ comments.push(comment.trim());
280
+ comment = '';
281
+ if (lastChar !== '@' && address.charAt(i + 1) !== '@') {
282
+ result += ' ';
283
+ lastChar = ' ';
284
+ }
285
+ }
286
+ else {
287
+ comment += chr;
288
+ }
289
+ continue;
290
+ }
291
+ if (closer) {
292
+ if (chr === '\\' && closer === '"' && i < len - 1) {
293
+ result += chr + address.charAt(++i);
294
+ lastChar = address.charAt(i);
295
+ continue;
296
+ }
297
+ if (chr === closer) {
298
+ closer = '';
299
+ }
300
+ }
301
+ else if (chr === '"') {
302
+ closer = '"';
303
+ }
304
+ else if (chr === '[') {
305
+ closer = ']';
306
+ }
307
+ else if (chr === '(') {
308
+ depth = 1;
309
+ continue;
310
+ }
311
+ result += chr;
312
+ lastChar = chr;
313
+ }
314
+ if (depth) {
315
+ // an unterminated comment runs to the end of the address
316
+ comments.push(comment.trim());
317
+ }
318
+ return { address: result.trim(), comments: comments.filter(text => text) };
319
+ }
245
320
  /**
246
321
  * Converts tokens for a single address into an address object
247
322
  *
@@ -353,7 +428,7 @@ function _handleAddress(tokens, depth) {
353
428
  // Parse group members, but flatten any nested groups (RFC 5322 doesn't allow nesting)
354
429
  let groupMembers = [];
355
430
  if (data.group.length) {
356
- const parsedGroup = addressparser(data.group.join(','), { _depth: depth + 1 });
431
+ const parsedGroup = _parseAddressList(data.group.join(','), depth + 1);
357
432
  parsedGroup.forEach(member => {
358
433
  if (member.group) {
359
434
  groupMembers = groupMembers.concat(member.group);
@@ -369,6 +444,24 @@ function _handleAddress(tokens, depth) {
369
444
  });
370
445
  }
371
446
  else {
447
+ // Comments come out of the angle-addr before anything asks whether one was found, so
448
+ // that brackets holding nothing but a comment read the same as empty ones
449
+ const addressComments = [];
450
+ const addressParts = [];
451
+ for (const part of data.address) {
452
+ if (part.indexOf('(') < 0) {
453
+ addressParts.push(part);
454
+ continue;
455
+ }
456
+ const stripped = _stripAddressComments(part);
457
+ for (const comment of stripped.comments) {
458
+ addressComments.push(comment);
459
+ }
460
+ if (stripped.address) {
461
+ addressParts.push(stripped.address);
462
+ }
463
+ }
464
+ data.address = addressParts;
372
465
  // If no address was found, try to detect one from regular text
373
466
  if (!data.address.length && data.text.length) {
374
467
  for (let i = data.text.length - 1; i >= 0; i--) {
@@ -422,7 +515,13 @@ function _handleAddress(tokens, depth) {
422
515
  // Join values with spaces
423
516
  data.text = data.text.join(' ');
424
517
  data.address = data.address.join(' ');
425
- if (addressFromQuotedText && data.text) {
518
+ if (addressFromQuotedText && data.text.indexOf('@') >= 0) {
519
+ // A quoted run with no '@' in it is a display name and nothing else, so it stays
520
+ // where it is. Moving it over anyway made a comment the mailbox was read from:
521
+ // '"Display Name" <(a comment)>' handed on 'Display Name' as the address with the
522
+ // comment as the name, and a quoted name holding a ',' or a ';' became an address
523
+ // that reads as two recipients once a consumer writes it back into a header.
524
+ //
426
525
  // The mailbox is still sitting in the text, so it moves over here and is quoted
427
526
  // before the recovery below rather than after it. Anything else the text holds
428
527
  // came along with it: a comment ends the domain but leaves the atoms behind it in
@@ -435,6 +534,10 @@ function _handleAddress(tokens, depth) {
435
534
  data.text = '';
436
535
  }
437
536
  _recoverAddrSpec(data);
537
+ // a comment names the mailbox only when nothing else does, as one outside the brackets
538
+ if (!data.text && addressComments.length) {
539
+ data.text = addressComments.join(' ');
540
+ }
438
541
  const address = {
439
542
  address: data.address || data.text || '',
440
543
  name: data.text || data.address || ''
@@ -465,6 +568,7 @@ class Tokenizer {
465
568
  this.node = null;
466
569
  this.escaped = false;
467
570
  this.inDomainLiteral = false;
571
+ this.afterAt = false;
468
572
  this.list = [];
469
573
  /**
470
574
  * Operator tokens and which tokens are expected to end the sequence
@@ -508,17 +612,23 @@ class Tokenizer {
508
612
  * Checks if a character is an operator or text and acts accordingly
509
613
  *
510
614
  * @param chr Character from the address field
615
+ * @param nextChr Character following chr, null at the end of the field
511
616
  */
512
617
  checkChar(chr, nextChr) {
513
- // Track RFC 5322 domain-literals ("[" *dtext "]"). Operator characters such
514
- // as the ":" of an IPv6 address-literal (user@[IPv6:2001:db8::1]) are dtext
515
- // and must not be treated as the group delimiter while inside the brackets.
516
- // Quoted strings and comments are handled separately via operatorExpecting,
517
- // so only enter this state when no operator is open. The list separators ","
518
- // and ";" are the exception: they always end the literal (and split the
519
- // address list) so that an unclosed "[" cannot swallow later recipients.
618
+ // Track RFC 5322 domain-literals ("[" *dtext "]"). The ":" of an IPv6
619
+ // address-literal (user@[IPv6:2001:db8::1]) is dtext and must not be treated as
620
+ // the group delimiter while inside the brackets. That is the only operator the
621
+ // literal hides: letting it hide the others as well meant a "[" could turn the
622
+ // comment, quoted string or angle-addr after it into text and pick a different
623
+ // mailbox, '[ ( ] <a@victim.com> ) <b@evil.com>' yielded a@victim.com where
624
+ // RFC 5322 reads b@evil.com. A "[" also only opens a literal right after the "@"
625
+ // of an addr-spec, so the group delimiter of a display name holding one stays
626
+ // intact. Quoted strings and comments are handled separately via
627
+ // operatorExpecting, so only enter this state when no operator is open. The list
628
+ // separators "," and ";" always end the literal (and split the address list) so
629
+ // that an unclosed "[" cannot swallow later recipients.
520
630
  if (!this.escaped && !this.operatorExpecting) {
521
- if (!this.inDomainLiteral && chr === '[') {
631
+ if (!this.inDomainLiteral && chr === '[' && this.afterAt) {
522
632
  this.inDomainLiteral = true;
523
633
  }
524
634
  else if (this.inDomainLiteral && (chr === ']' || chr === ',' || chr === ';')) {
@@ -538,17 +648,24 @@ class Tokenizer {
538
648
  }
539
649
  this.list.push(this.node);
540
650
  this.node = null;
651
+ if (chr !== ')') {
652
+ // a comment is folding whitespace, it does not part the "@" from the "["
653
+ this.afterAt = false;
654
+ }
541
655
  this.operatorExpecting = '';
542
656
  this.escaped = false;
543
657
  return;
544
658
  }
545
- else if (!this.operatorExpecting && !this.inDomainLiteral && chr in this.operators) {
659
+ else if (!this.operatorExpecting && !(this.inDomainLiteral && chr === ':') && chr in this.operators) {
546
660
  this.node = {
547
661
  type: 'operator',
548
662
  value: chr
549
663
  };
550
664
  this.list.push(this.node);
551
665
  this.node = null;
666
+ if (chr !== '(') {
667
+ this.afterAt = false;
668
+ }
552
669
  this.operatorExpecting = this.operators[chr];
553
670
  this.escaped = false;
554
671
  return;
@@ -572,6 +689,11 @@ class Tokenizer {
572
689
  if (chr.charCodeAt(0) >= 0x21 || [' ', '\t'].includes(chr)) {
573
690
  // skip command bytes
574
691
  this.node.value += chr;
692
+ // text inside a quoted string or a comment is not part of an addr-spec. Tracked
693
+ // as it goes rather than read back off the value (see lastChars in _handleAddress)
694
+ if (!this.operatorExpecting && chr !== ' ' && chr !== '\t') {
695
+ this.afterAt = chr === '@';
696
+ }
575
697
  }
576
698
  this.escaped = false;
577
699
  }
@@ -582,9 +704,19 @@ class Tokenizer {
582
704
  * malicious input that could cause stack overflow.
583
705
  */
584
706
  const MAX_NESTED_GROUP_DEPTH = 50;
585
- function addressparser(str, options) {
586
- options = options || {};
587
- const depth = options._depth || 0;
707
+ /**
708
+ * Parses an address list, recursing into the groups it holds.
709
+ *
710
+ * The depth is threaded through the calls rather than carried in an options object, so a
711
+ * caller supplied one can not seed it and lift the recursion limit: `{ _depth: -1e9 }`
712
+ * bought a billion levels of nesting and turned the guard below into the stack overflow it
713
+ * is there to prevent.
714
+ *
715
+ * @param str Address field
716
+ * @param depth Current recursion depth for nested group protection
717
+ * @return An array of address objects
718
+ */
719
+ function _parseAddressList(str, depth) {
588
720
  // Prevent stack overflow from deeply nested groups (DoS protection)
589
721
  if (depth > MAX_NESTED_GROUP_DEPTH) {
590
722
  return [];
@@ -593,7 +725,7 @@ function addressparser(str, options) {
593
725
  const tokens = tokenizer.tokenize();
594
726
  const addresses = [];
595
727
  let address = [];
596
- let parsedAddresses = [];
728
+ const parsedAddresses = [];
597
729
  tokens.forEach(token => {
598
730
  if (token.type === 'operator' && (token.value === ',' || token.value === ';')) {
599
731
  if (address.length) {
@@ -634,8 +766,11 @@ function addressparser(str, options) {
634
766
  }
635
767
  }
636
768
  mergedAddresses.reverse();
637
- parsedAddresses = mergedAddresses;
638
- if (options.flatten) {
769
+ return mergedAddresses;
770
+ }
771
+ function addressparser(str, options) {
772
+ const parsedAddresses = _parseAddressList(str, 0);
773
+ if (options?.flatten) {
639
774
  const flatAddresses = [];
640
775
  const walkAddressList = (list) => {
641
776
  list.forEach(entry => {
@@ -1,6 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const node_stream_1 = require("node:stream");
4
+ /**
5
+ * Drops the SP and HTAB from both ends of a field name.
6
+ *
7
+ * An index scan rather than `/^[ \t]+|[ \t]+$/g`, which retries the trailing branch at
8
+ * every offset of a blank run that is followed by other text: the run is consumed greedily,
9
+ * `$` fails, and the engine gives the characters back one at a time before moving on to
10
+ * start the same walk one offset further in. A field name carrying a 128 KiB run of spaces
11
+ * between two atoms took about 6.7 seconds to trim, and the cost grows with its square.
12
+ *
13
+ * Not `.trim()`, which takes the other Unicode spaces along: an NBSP in front of a field
14
+ * name would come off and select the name into the signed set, where the relaxed
15
+ * canonicalization in sign.ts deliberately leaves everything but SP and HTAB alone.
16
+ *
17
+ * @param str Field name to trim
18
+ * @return The field name without the surrounding SP and HTAB
19
+ */
20
+ function _trimFieldName(str) {
21
+ let start = 0;
22
+ let end = str.length;
23
+ while (start < end && (str.charCodeAt(start) === 0x20 || str.charCodeAt(start) === 0x09)) {
24
+ start++;
25
+ }
26
+ while (end > start && (str.charCodeAt(end - 1) === 0x20 || str.charCodeAt(end - 1) === 0x09)) {
27
+ end--;
28
+ }
29
+ return str.slice(start, end);
30
+ }
4
31
  /**
5
32
  * MessageParser instance is a transform stream that separates message headers
6
33
  * from the rest of the body. Headers are emitted with the 'headers' event. Message
@@ -143,10 +170,7 @@ class MessageParser extends node_stream_1.Transform {
143
170
  return lines
144
171
  .filter(line => /[^ \t\r]/.test(line))
145
172
  .map(line => ({
146
- key: line
147
- .substr(0, line.indexOf(':'))
148
- .replace(/^[ \t]+|[ \t]+$/g, '')
149
- .toLowerCase(),
173
+ key: _trimFieldName(line.substr(0, line.indexOf(':'))).toLowerCase(),
150
174
  line
151
175
  }));
152
176
  }
@@ -36,6 +36,7 @@ export interface DKIMRelaxedHeaders {
36
36
  * Returns DKIM signature header line
37
37
  *
38
38
  * @param headers Parsed headers object from MessageParser
39
+ * @param hashAlgo Hash algorithm the body hash was calculated with, for example "sha256"
39
40
  * @param bodyHash Base64 encoded hash of the message
40
41
  * @param options DKIM options
41
42
  * @param options.domainName Domain name to be signed for
@@ -52,6 +52,7 @@ function unsupportedHashAlgoError(hashAlgo) {
52
52
  * Returns DKIM signature header line
53
53
  *
54
54
  * @param headers Parsed headers object from MessageParser
55
+ * @param hashAlgo Hash algorithm the body hash was calculated with, for example "sha256"
55
56
  * @param bodyHash Base64 encoded hash of the message
56
57
  * @param options DKIM options
57
58
  * @param options.domainName Domain name to be signed for
@@ -193,9 +193,15 @@ declare class Mail<out T = SentMessageInfo, out D extends TransportOptions = Tra
193
193
  * Sends an email using the preselected transport object
194
194
  *
195
195
  * @param data E-data description
196
- * @param callback Callback to run once the sending succeeded or failed
196
+ * @returns Promise that resolves with the result of the send
197
197
  */
198
198
  sendMail(data: SendMailOptions): Promise<T>;
199
+ /**
200
+ * Sends an email using the preselected transport object
201
+ *
202
+ * @param data E-data description
203
+ * @param callback Callback to run once the sending succeeded or failed
204
+ */
199
205
  sendMail(data: SendMailOptions, callback: SendMailCallback<T>): void;
200
206
  getVersionString(): string;
201
207
  /**
@@ -59,6 +59,7 @@ export declare function quoteString(value?: string): string;
59
59
  * no need to encode the values in any way. If the value is plaintext but has
60
60
  * longer lines then allowed, then use format=flowed
61
61
  *
62
+ * @param str Multi line string to check
62
63
  * @param lineLength Max line length to check for
63
64
  * @returns Returns true if there is at least one line longer than lineLength chars
64
65
  */
@@ -100,9 +101,9 @@ export declare function buildHeaderValue(structured: StructuredHeaderValue): str
100
101
  * title*0*=utf-8''unicode
101
102
  * title*1*=%20string
102
103
  *
104
+ * @param key Parameter name the generated keys are built from, for example title
103
105
  * @param data String to be encoded
104
106
  * @param [maxLength=50] Max length for generated chunks
105
- * @param [fromCharset='UTF-8'] Source sharacter set
106
107
  * @return A list of encoded keys and headers
107
108
  */
108
109
  export declare function buildHeaderParam(key: string, data: string | Buffer, maxLength?: number): EncodedHeaderParam[];