nodemailer 10.4.0 → 10.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## [10.4.1](https://github.com/nodemailer/nodemailer/compare/v10.4.0...v10.4.1) (2026-11-10)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **addressparser:** read whitespace and comments around a dot of the domain as CFWS ([c2b9c41](https://github.com/nodemailer/nodemailer/commit/c2b9c41bb81b2294ebadd294ad15ff035a17d0a5))
9
+ * **mime-node:** hand a domain to the UTS-46 mapper without lowercasing it first ([093e4dd](https://github.com/nodemailer/nodemailer/commit/093e4dd60af8a21e7f06a49c7f889291728e966a))
10
+
3
11
  ## [10.4.0](https://github.com/nodemailer/nodemailer/compare/v10.3.1...v10.4.0) (2026-11-07)
4
12
 
5
13
 
@@ -48,6 +48,30 @@ class TokenList {
48
48
  this.slots[at + 2] = end;
49
49
  return this.length++;
50
50
  }
51
+ /**
52
+ * Offset of the first character of a token that is part of its value. A text run that is
53
+ * no plain slice of the field still spans the whitespace and control characters its value
54
+ * is trimmed of.
55
+ */
56
+ contentStart(index) {
57
+ let start = this.slots[index * 3 + 1];
58
+ const end = this.slots[index * 3 + 2];
59
+ while (start < end && _isDroppedCode(this.str.charCodeAt(start))) {
60
+ start++;
61
+ }
62
+ return start;
63
+ }
64
+ /**
65
+ * Offset just past the last character of a token that is part of its value
66
+ */
67
+ contentEnd(index) {
68
+ const start = this.slots[index * 3 + 1];
69
+ let end = this.slots[index * 3 + 2];
70
+ while (end > start && _isDroppedCode(this.str.charCodeAt(end - 1))) {
71
+ end--;
72
+ }
73
+ return end;
74
+ }
51
75
  /**
52
76
  * The character of an operator token, an empty string for a text run
53
77
  */
@@ -183,6 +207,44 @@ function _isSpaceCode(code) {
183
207
  code === 0x3000 ||
184
208
  code === 0xfeff);
185
209
  }
210
+ /**
211
+ * Checks for the whitespace RFC 5322 folding whitespace is made of: SP and HTAB, plus the
212
+ * line break a fold carries. The other characters _isSpaceCode accepts are atext under
213
+ * RFC 6532, and parsers disagree on them: mailauth keeps U+00A0 in a domain, so joining a
214
+ * domain across one names a domain that reader never sees
215
+ *
216
+ * @param code Character code
217
+ * @return true if the character is folding whitespace
218
+ */
219
+ function _isFoldingSpaceCode(code) {
220
+ return code === 0x20 || code === 0x09 || code === 0x0d || code === 0x0a;
221
+ }
222
+ /**
223
+ * Checks if every character in a stretch of the field is folding whitespace
224
+ *
225
+ * @param str The field
226
+ * @param from Offset of the first character
227
+ * @param to Offset just past the last one
228
+ * @return true if the stretch holds nothing but folding whitespace
229
+ */
230
+ function _isFoldingGap(str, from, to) {
231
+ for (let i = from; i < to; i++) {
232
+ if (!_isFoldingSpaceCode(str.charCodeAt(i))) {
233
+ return false;
234
+ }
235
+ }
236
+ return true;
237
+ }
238
+ /**
239
+ * Checks for a character the value of a text run is trimmed of, or leaves out: whitespace,
240
+ * C0 controls and DEL
241
+ *
242
+ * @param code Character code
243
+ * @return true if the character is not part of the value at the edge of a run
244
+ */
245
+ function _isDroppedCode(code) {
246
+ return code < 0x20 || code === 0x7f || _isSpaceCode(code);
247
+ }
186
248
  /**
187
249
  * The characters JS `\w` matches without the unicode flag, the set the `\b` in
188
250
  * LOOSE_TEXT_ADDR is read against. charCodeAt off either end of the string gives NaN,
@@ -233,6 +295,9 @@ const LEADING_QUOTED_STRING = /^"(?:[^"\\]|\\[\s\S])*"/;
233
295
  * The scan is by index, a pattern such as /\s+@/ backtracks over a long whitespace run that
234
296
  * no '@' follows.
235
297
  *
298
+ * The whitespace around the dots of the domain that follows is dropped as well, see
299
+ * _joinDomainDotSpacing.
300
+ *
236
301
  * @param value Value holding the '@'
237
302
  * @param at Offset of the '@', or -1
238
303
  * @return The value with the whitespace beside that '@' removed
@@ -249,7 +314,86 @@ function _joinAtSpacing(value, at) {
249
314
  while (end < value.length && _isSpaceCode(value.charCodeAt(end))) {
250
315
  end++;
251
316
  }
252
- return start === at && end === at + 1 ? value : value.slice(0, start) + '@' + value.slice(end);
317
+ const joined = start === at && end === at + 1 ? value : value.slice(0, start) + '@' + value.slice(end);
318
+ return _joinDomainDotSpacing(joined, start);
319
+ }
320
+ // The ASCII atext characters: printable, and none of the RFC 5322 specials
321
+ const ASCII_ATEXT = new Uint8Array(0x80);
322
+ for (let code = 0x21; code < 0x7f; code++) {
323
+ ASCII_ATEXT[code] = '()<>[]:;@\\,."'.indexOf(String.fromCharCode(code)) < 0 ? 1 : 0;
324
+ }
325
+ /**
326
+ * Checks if a character can be part of an atom: anything but the specials, whitespace and
327
+ * the control characters (RFC 5322 3.2.3, with non-ASCII allowed as RFC 6532 does)
328
+ *
329
+ * @param code Character code
330
+ * @return true if the character is atext
331
+ */
332
+ function _isAtextCode(code) {
333
+ return code < 0x80 ? ASCII_ATEXT[code] === 1 : !_isSpaceCode(code);
334
+ }
335
+ /**
336
+ * Drops the whitespace around the dots of the domain behind the '@' at an offset.
337
+ *
338
+ * obs-domain is atoms with CFWS around the dots (RFC 5322 4.4), so 'user@victim.example
339
+ * .allowed.example' names user@victim.example.allowed.example. Read as two runs, the domain
340
+ * ended at the whitespace and the envelope went to victim.example, a different domain than
341
+ * the one an RFC 5322 parser, and an application validating the address with one, reads
342
+ * (GHSA-3q53-mvfw-q9v8). A comment around a dot reaches here as whitespace.
343
+ *
344
+ * Only SP, HTAB and a fold count as the whitespace, see _isFoldingSpaceCode.
345
+ *
346
+ * Only a dot with an atom on both sides joins, as for a conformant parser: whitespace that
347
+ * is not beside a dot ends the domain, and so does a dot that no atom follows, which keeps
348
+ * 'user@example.com .' from becoming a domain with a trailing dot. A domain literal is left
349
+ * alone. Everything from where the domain ends is kept as it is.
350
+ *
351
+ * @param value Value holding the '@'
352
+ * @param at Offset of the '@'
353
+ * @return The value with the whitespace around the dots of that domain removed
354
+ */
355
+ function _joinDomainDotSpacing(value, at) {
356
+ const len = value.length;
357
+ // '[' is no atext, so a domain literal ends the walk before it starts
358
+ let pos = at + 1;
359
+ let spaced = false;
360
+ for (;;) {
361
+ const labelStart = pos;
362
+ while (pos < len && _isAtextCode(value.charCodeAt(pos))) {
363
+ pos++;
364
+ }
365
+ if (pos === labelStart) {
366
+ break;
367
+ }
368
+ // the dot, with the whitespace on either side of it, and the label behind it
369
+ let next = pos;
370
+ while (next < len && _isFoldingSpaceCode(value.charCodeAt(next))) {
371
+ next++;
372
+ }
373
+ if (value.charCodeAt(next) !== 0x2e) {
374
+ break;
375
+ }
376
+ next++;
377
+ while (next < len && _isFoldingSpaceCode(value.charCodeAt(next))) {
378
+ next++;
379
+ }
380
+ if (next >= len || !_isAtextCode(value.charCodeAt(next))) {
381
+ break;
382
+ }
383
+ spaced = spaced || next !== pos + 1;
384
+ pos = next;
385
+ }
386
+ if (!spaced) {
387
+ return value;
388
+ }
389
+ // every whitespace character the walk covered sits beside a dot
390
+ let domain = '';
391
+ for (let k = at + 1; k < pos; k++) {
392
+ if (!_isFoldingSpaceCode(value.charCodeAt(k))) {
393
+ domain += value.charAt(k);
394
+ }
395
+ }
396
+ return value.slice(0, at + 1) + domain + value.slice(pos);
253
397
  }
254
398
  /**
255
399
  * Drops the whitespace beside the '@' that splits the domain off a value. That is the '@'
@@ -553,6 +697,15 @@ function _collectAddressParts(tokens, from, to) {
553
697
  // whether the last text run holds nothing but quoted text so far, which is what a quoted
554
698
  // local part is until the '@' after it joins the run
555
699
  let lastTextPureQuoted = false;
700
+ // whether the last text run holds an unquoted '@', so that it runs on into a domain, and
701
+ // whether nothing but comments has come since it, see the join below
702
+ let lastTextHasAt = false;
703
+ let lastTextOpen = false;
704
+ // Where the last text run, or the last comment since it, ended in the field, and whether
705
+ // everything between it and the comments since was folding whitespace. The tokens are
706
+ // trimmed of any whitespace, so this is read off the field itself.
707
+ let gapFrom = 0;
708
+ let gapsFolding = true;
556
709
  // Last character of the run each state is currently accumulating. Reading it back off
557
710
  // the accumulator with slice(-1) makes the engine flatten the whole growing string on
558
711
  // every token, which is quadratic over an address built from many comment-joined atoms
@@ -570,18 +723,27 @@ function _collectAddressParts(tokens, from, to) {
570
723
  case '<':
571
724
  state = 'address';
572
725
  insideQuotes = false;
726
+ lastTextOpen = false;
573
727
  break;
574
728
  case '(':
575
729
  state = 'comment';
576
730
  insideQuotes = false;
731
+ gapsFolding = gapsFolding && _isFoldingGap(tokens.str, gapFrom, tokens.contentStart(i));
577
732
  break;
578
733
  case '"':
579
734
  insideQuotes = !insideQuotes;
580
735
  state = 'text';
736
+ lastTextOpen = false;
581
737
  break;
582
738
  default:
583
739
  state = 'text';
584
740
  insideQuotes = false;
741
+ if (value !== ')') {
742
+ lastTextOpen = false;
743
+ }
744
+ else {
745
+ gapFrom = tokens.contentEnd(i);
746
+ }
585
747
  break;
586
748
  }
587
749
  }
@@ -598,8 +760,23 @@ function _collectAddressParts(tokens, from, to) {
598
760
  // of the '@', but it cannot join two atoms into one: gluing across it would read
599
761
  // 'user@example.com(x)evil.com' as the single domain 'example.comevil.com' and
600
762
  // deliver to a domain the sender never named.
763
+ // A comment beside a dot of a domain is CFWS inside obs-domain, with or without
764
+ // folding whitespace around it, so 'user@victim.example(x).allowed.example' names
765
+ // one domain (GHSA-3q53-mvfw-q9v8). Any other whitespace in between keeps them apart.
766
+ // A ')' always leaves the walk in unquoted text, so neither needs checking here.
767
+ // Neither join across a comment takes in a second '@' once the run holds one: the
768
+ // address would then split at the last '@', and 'user@company(x).com@attacker.net',
769
+ // which an RFC 5322 parser reads as user@company.com, would go to attacker.net.
601
770
  const parts = data[state];
602
- const joins = prevNoBreak && parts.length && (prevOperator !== ')' || lastChars[state] === '@' || value.charAt(0) === '@');
771
+ const secondAt = lastTextHasAt && prevOperator === ')' && value.indexOf('@') >= 0;
772
+ const joinsDomain = !secondAt &&
773
+ lastTextOpen &&
774
+ lastTextHasAt &&
775
+ prevOperator === ')' &&
776
+ (lastChars.text === '.' || value.charAt(0) === '.') &&
777
+ gapsFolding &&
778
+ _isFoldingGap(tokens.str, gapFrom, tokens.contentStart(i));
779
+ const joins = joinsDomain || (!secondAt && prevNoBreak && parts.length > 0 && (prevOperator !== ')' || lastChars[state] === '@' || value.charAt(0) === '@'));
603
780
  if (joins) {
604
781
  const last = data[state].length - 1;
605
782
  if (state === 'text' && !insideQuotes) {
@@ -624,6 +801,12 @@ function _collectAddressParts(tokens, from, to) {
624
801
  lastTextPureQuoted = insideQuotes;
625
802
  }
626
803
  }
804
+ if (state === 'text') {
805
+ lastTextHasAt = (joins && lastTextHasAt) || (!insideQuotes && value.indexOf('@') >= 0);
806
+ lastTextOpen = true;
807
+ gapFrom = tokens.contentEnd(i);
808
+ gapsFolding = true;
809
+ }
627
810
  }
628
811
  }
629
812
  // If there is no text but a comment, replace the two. A comment is never part of a
@@ -147,9 +147,14 @@ function exceedsDomainLimits(domain) {
147
147
  *
148
148
  * Anything the URL parser does not accept as a hostname, an address literal such as
149
149
  * '[127.0.0.1]' included, comes back empty and falls through to the bundled codec, which
150
- * leaves those as they were supplied.
150
+ * leaves those as they were supplied apart from lowercasing them.
151
151
  *
152
- * @param domain Domain to encode, already lowercased by the caller
152
+ * The mapper gets the domain as supplied, since UTS-46 does its own case mapping and
153
+ * toLowerCase() differs from it: it turns U+1E9E into U+00DF where Node 20 and 22 map it
154
+ * to 'ss', and a word-final U+03A3 into U+03C2 where UTS-46 gives U+03C3. Lowercasing
155
+ * first sent 'user@stra\u1E9Ee.de', which a validator reads as strasse.de, to xn--strae-oqa.de.
156
+ *
157
+ * @param domain Domain to encode
153
158
  * @param toUnicode Return the U-label form instead of the A-label form
154
159
  * @return Encoded domain
155
160
  */
@@ -165,6 +170,7 @@ function normalizeDomain(domain, toUnicode) {
165
170
  return mapped;
166
171
  }
167
172
  }
173
+ domain = domain.toLowerCase();
168
174
  if (exceedsDomainLimits(domain)) {
169
175
  // too long to be a domain whichever way it is encoded, keep it as supplied
170
176
  return domain;
@@ -1538,7 +1544,7 @@ class MimeNode {
1538
1544
  // symmetry on both sides of the '@' rather than being encoded to an A-label
1539
1545
  const smtputf8 = /[\x80-\uFFFF]/.test(user);
1540
1546
  try {
1541
- encodedDomain = normalizeDomain(domain.toLowerCase(), smtputf8);
1547
+ encodedDomain = normalizeDomain(domain, smtputf8);
1542
1548
  }
1543
1549
  catch (_err) {
1544
1550
  // keep domain as supplied
@@ -1,3 +1,3 @@
1
1
  export declare const name = "nodemailer";
2
- export declare const version = "10.4.0";
2
+ export declare const version = "10.4.1";
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.4.0';
6
+ exports.version = '10.4.1';
7
7
  exports.homepage = 'https://nodemailer.com/';
@@ -609,6 +609,13 @@ exports.services = {
609
609
  "host": "mail.smtp2go.com",
610
610
  "port": 2525
611
611
  },
612
+ "SpacePost": {
613
+ "description": "SpacePost",
614
+ "host": "smtp.spacepost.dev",
615
+ "port": 25976,
616
+ "secure": false,
617
+ "requireTLS": true
618
+ },
612
619
  "Sparkpost": {
613
620
  "description": "SparkPost",
614
621
  "aliases": [
@@ -46,6 +46,30 @@ class TokenList {
46
46
  this.slots[at + 2] = end;
47
47
  return this.length++;
48
48
  }
49
+ /**
50
+ * Offset of the first character of a token that is part of its value. A text run that is
51
+ * no plain slice of the field still spans the whitespace and control characters its value
52
+ * is trimmed of.
53
+ */
54
+ contentStart(index) {
55
+ let start = this.slots[index * 3 + 1];
56
+ const end = this.slots[index * 3 + 2];
57
+ while (start < end && _isDroppedCode(this.str.charCodeAt(start))) {
58
+ start++;
59
+ }
60
+ return start;
61
+ }
62
+ /**
63
+ * Offset just past the last character of a token that is part of its value
64
+ */
65
+ contentEnd(index) {
66
+ const start = this.slots[index * 3 + 1];
67
+ let end = this.slots[index * 3 + 2];
68
+ while (end > start && _isDroppedCode(this.str.charCodeAt(end - 1))) {
69
+ end--;
70
+ }
71
+ return end;
72
+ }
49
73
  /**
50
74
  * The character of an operator token, an empty string for a text run
51
75
  */
@@ -181,6 +205,44 @@ function _isSpaceCode(code) {
181
205
  code === 0x3000 ||
182
206
  code === 0xfeff);
183
207
  }
208
+ /**
209
+ * Checks for the whitespace RFC 5322 folding whitespace is made of: SP and HTAB, plus the
210
+ * line break a fold carries. The other characters _isSpaceCode accepts are atext under
211
+ * RFC 6532, and parsers disagree on them: mailauth keeps U+00A0 in a domain, so joining a
212
+ * domain across one names a domain that reader never sees
213
+ *
214
+ * @param code Character code
215
+ * @return true if the character is folding whitespace
216
+ */
217
+ function _isFoldingSpaceCode(code) {
218
+ return code === 0x20 || code === 0x09 || code === 0x0d || code === 0x0a;
219
+ }
220
+ /**
221
+ * Checks if every character in a stretch of the field is folding whitespace
222
+ *
223
+ * @param str The field
224
+ * @param from Offset of the first character
225
+ * @param to Offset just past the last one
226
+ * @return true if the stretch holds nothing but folding whitespace
227
+ */
228
+ function _isFoldingGap(str, from, to) {
229
+ for (let i = from; i < to; i++) {
230
+ if (!_isFoldingSpaceCode(str.charCodeAt(i))) {
231
+ return false;
232
+ }
233
+ }
234
+ return true;
235
+ }
236
+ /**
237
+ * Checks for a character the value of a text run is trimmed of, or leaves out: whitespace,
238
+ * C0 controls and DEL
239
+ *
240
+ * @param code Character code
241
+ * @return true if the character is not part of the value at the edge of a run
242
+ */
243
+ function _isDroppedCode(code) {
244
+ return code < 0x20 || code === 0x7f || _isSpaceCode(code);
245
+ }
184
246
  /**
185
247
  * The characters JS `\w` matches without the unicode flag, the set the `\b` in
186
248
  * LOOSE_TEXT_ADDR is read against. charCodeAt off either end of the string gives NaN,
@@ -231,6 +293,9 @@ const LEADING_QUOTED_STRING = /^"(?:[^"\\]|\\[\s\S])*"/;
231
293
  * The scan is by index, a pattern such as /\s+@/ backtracks over a long whitespace run that
232
294
  * no '@' follows.
233
295
  *
296
+ * The whitespace around the dots of the domain that follows is dropped as well, see
297
+ * _joinDomainDotSpacing.
298
+ *
234
299
  * @param value Value holding the '@'
235
300
  * @param at Offset of the '@', or -1
236
301
  * @return The value with the whitespace beside that '@' removed
@@ -247,7 +312,86 @@ function _joinAtSpacing(value, at) {
247
312
  while (end < value.length && _isSpaceCode(value.charCodeAt(end))) {
248
313
  end++;
249
314
  }
250
- return start === at && end === at + 1 ? value : value.slice(0, start) + '@' + value.slice(end);
315
+ const joined = start === at && end === at + 1 ? value : value.slice(0, start) + '@' + value.slice(end);
316
+ return _joinDomainDotSpacing(joined, start);
317
+ }
318
+ // The ASCII atext characters: printable, and none of the RFC 5322 specials
319
+ const ASCII_ATEXT = new Uint8Array(0x80);
320
+ for (let code = 0x21; code < 0x7f; code++) {
321
+ ASCII_ATEXT[code] = '()<>[]:;@\\,."'.indexOf(String.fromCharCode(code)) < 0 ? 1 : 0;
322
+ }
323
+ /**
324
+ * Checks if a character can be part of an atom: anything but the specials, whitespace and
325
+ * the control characters (RFC 5322 3.2.3, with non-ASCII allowed as RFC 6532 does)
326
+ *
327
+ * @param code Character code
328
+ * @return true if the character is atext
329
+ */
330
+ function _isAtextCode(code) {
331
+ return code < 0x80 ? ASCII_ATEXT[code] === 1 : !_isSpaceCode(code);
332
+ }
333
+ /**
334
+ * Drops the whitespace around the dots of the domain behind the '@' at an offset.
335
+ *
336
+ * obs-domain is atoms with CFWS around the dots (RFC 5322 4.4), so 'user@victim.example
337
+ * .allowed.example' names user@victim.example.allowed.example. Read as two runs, the domain
338
+ * ended at the whitespace and the envelope went to victim.example, a different domain than
339
+ * the one an RFC 5322 parser, and an application validating the address with one, reads
340
+ * (GHSA-3q53-mvfw-q9v8). A comment around a dot reaches here as whitespace.
341
+ *
342
+ * Only SP, HTAB and a fold count as the whitespace, see _isFoldingSpaceCode.
343
+ *
344
+ * Only a dot with an atom on both sides joins, as for a conformant parser: whitespace that
345
+ * is not beside a dot ends the domain, and so does a dot that no atom follows, which keeps
346
+ * 'user@example.com .' from becoming a domain with a trailing dot. A domain literal is left
347
+ * alone. Everything from where the domain ends is kept as it is.
348
+ *
349
+ * @param value Value holding the '@'
350
+ * @param at Offset of the '@'
351
+ * @return The value with the whitespace around the dots of that domain removed
352
+ */
353
+ function _joinDomainDotSpacing(value, at) {
354
+ const len = value.length;
355
+ // '[' is no atext, so a domain literal ends the walk before it starts
356
+ let pos = at + 1;
357
+ let spaced = false;
358
+ for (;;) {
359
+ const labelStart = pos;
360
+ while (pos < len && _isAtextCode(value.charCodeAt(pos))) {
361
+ pos++;
362
+ }
363
+ if (pos === labelStart) {
364
+ break;
365
+ }
366
+ // the dot, with the whitespace on either side of it, and the label behind it
367
+ let next = pos;
368
+ while (next < len && _isFoldingSpaceCode(value.charCodeAt(next))) {
369
+ next++;
370
+ }
371
+ if (value.charCodeAt(next) !== 0x2e) {
372
+ break;
373
+ }
374
+ next++;
375
+ while (next < len && _isFoldingSpaceCode(value.charCodeAt(next))) {
376
+ next++;
377
+ }
378
+ if (next >= len || !_isAtextCode(value.charCodeAt(next))) {
379
+ break;
380
+ }
381
+ spaced = spaced || next !== pos + 1;
382
+ pos = next;
383
+ }
384
+ if (!spaced) {
385
+ return value;
386
+ }
387
+ // every whitespace character the walk covered sits beside a dot
388
+ let domain = '';
389
+ for (let k = at + 1; k < pos; k++) {
390
+ if (!_isFoldingSpaceCode(value.charCodeAt(k))) {
391
+ domain += value.charAt(k);
392
+ }
393
+ }
394
+ return value.slice(0, at + 1) + domain + value.slice(pos);
251
395
  }
252
396
  /**
253
397
  * Drops the whitespace beside the '@' that splits the domain off a value. That is the '@'
@@ -551,6 +695,15 @@ function _collectAddressParts(tokens, from, to) {
551
695
  // whether the last text run holds nothing but quoted text so far, which is what a quoted
552
696
  // local part is until the '@' after it joins the run
553
697
  let lastTextPureQuoted = false;
698
+ // whether the last text run holds an unquoted '@', so that it runs on into a domain, and
699
+ // whether nothing but comments has come since it, see the join below
700
+ let lastTextHasAt = false;
701
+ let lastTextOpen = false;
702
+ // Where the last text run, or the last comment since it, ended in the field, and whether
703
+ // everything between it and the comments since was folding whitespace. The tokens are
704
+ // trimmed of any whitespace, so this is read off the field itself.
705
+ let gapFrom = 0;
706
+ let gapsFolding = true;
554
707
  // Last character of the run each state is currently accumulating. Reading it back off
555
708
  // the accumulator with slice(-1) makes the engine flatten the whole growing string on
556
709
  // every token, which is quadratic over an address built from many comment-joined atoms
@@ -568,18 +721,27 @@ function _collectAddressParts(tokens, from, to) {
568
721
  case '<':
569
722
  state = 'address';
570
723
  insideQuotes = false;
724
+ lastTextOpen = false;
571
725
  break;
572
726
  case '(':
573
727
  state = 'comment';
574
728
  insideQuotes = false;
729
+ gapsFolding = gapsFolding && _isFoldingGap(tokens.str, gapFrom, tokens.contentStart(i));
575
730
  break;
576
731
  case '"':
577
732
  insideQuotes = !insideQuotes;
578
733
  state = 'text';
734
+ lastTextOpen = false;
579
735
  break;
580
736
  default:
581
737
  state = 'text';
582
738
  insideQuotes = false;
739
+ if (value !== ')') {
740
+ lastTextOpen = false;
741
+ }
742
+ else {
743
+ gapFrom = tokens.contentEnd(i);
744
+ }
583
745
  break;
584
746
  }
585
747
  }
@@ -596,8 +758,23 @@ function _collectAddressParts(tokens, from, to) {
596
758
  // of the '@', but it cannot join two atoms into one: gluing across it would read
597
759
  // 'user@example.com(x)evil.com' as the single domain 'example.comevil.com' and
598
760
  // deliver to a domain the sender never named.
761
+ // A comment beside a dot of a domain is CFWS inside obs-domain, with or without
762
+ // folding whitespace around it, so 'user@victim.example(x).allowed.example' names
763
+ // one domain (GHSA-3q53-mvfw-q9v8). Any other whitespace in between keeps them apart.
764
+ // A ')' always leaves the walk in unquoted text, so neither needs checking here.
765
+ // Neither join across a comment takes in a second '@' once the run holds one: the
766
+ // address would then split at the last '@', and 'user@company(x).com@attacker.net',
767
+ // which an RFC 5322 parser reads as user@company.com, would go to attacker.net.
599
768
  const parts = data[state];
600
- const joins = prevNoBreak && parts.length && (prevOperator !== ')' || lastChars[state] === '@' || value.charAt(0) === '@');
769
+ const secondAt = lastTextHasAt && prevOperator === ')' && value.indexOf('@') >= 0;
770
+ const joinsDomain = !secondAt &&
771
+ lastTextOpen &&
772
+ lastTextHasAt &&
773
+ prevOperator === ')' &&
774
+ (lastChars.text === '.' || value.charAt(0) === '.') &&
775
+ gapsFolding &&
776
+ _isFoldingGap(tokens.str, gapFrom, tokens.contentStart(i));
777
+ const joins = joinsDomain || (!secondAt && prevNoBreak && parts.length > 0 && (prevOperator !== ')' || lastChars[state] === '@' || value.charAt(0) === '@'));
601
778
  if (joins) {
602
779
  const last = data[state].length - 1;
603
780
  if (state === 'text' && !insideQuotes) {
@@ -622,6 +799,12 @@ function _collectAddressParts(tokens, from, to) {
622
799
  lastTextPureQuoted = insideQuotes;
623
800
  }
624
801
  }
802
+ if (state === 'text') {
803
+ lastTextHasAt = (joins && lastTextHasAt) || (!insideQuotes && value.indexOf('@') >= 0);
804
+ lastTextOpen = true;
805
+ gapFrom = tokens.contentEnd(i);
806
+ gapsFolding = true;
807
+ }
625
808
  }
626
809
  }
627
810
  // If there is no text but a comment, replace the two. A comment is never part of a
@@ -109,9 +109,14 @@ function exceedsDomainLimits(domain) {
109
109
  *
110
110
  * Anything the URL parser does not accept as a hostname, an address literal such as
111
111
  * '[127.0.0.1]' included, comes back empty and falls through to the bundled codec, which
112
- * leaves those as they were supplied.
112
+ * leaves those as they were supplied apart from lowercasing them.
113
113
  *
114
- * @param domain Domain to encode, already lowercased by the caller
114
+ * The mapper gets the domain as supplied, since UTS-46 does its own case mapping and
115
+ * toLowerCase() differs from it: it turns U+1E9E into U+00DF where Node 20 and 22 map it
116
+ * to 'ss', and a word-final U+03A3 into U+03C2 where UTS-46 gives U+03C3. Lowercasing
117
+ * first sent 'user@stra\u1E9Ee.de', which a validator reads as strasse.de, to xn--strae-oqa.de.
118
+ *
119
+ * @param domain Domain to encode
115
120
  * @param toUnicode Return the U-label form instead of the A-label form
116
121
  * @return Encoded domain
117
122
  */
@@ -127,6 +132,7 @@ function normalizeDomain(domain, toUnicode) {
127
132
  return mapped;
128
133
  }
129
134
  }
135
+ domain = domain.toLowerCase();
130
136
  if (exceedsDomainLimits(domain)) {
131
137
  // too long to be a domain whichever way it is encoded, keep it as supplied
132
138
  return domain;
@@ -1500,7 +1506,7 @@ class MimeNode {
1500
1506
  // symmetry on both sides of the '@' rather than being encoded to an A-label
1501
1507
  const smtputf8 = /[\x80-\uFFFF]/.test(user);
1502
1508
  try {
1503
- encodedDomain = normalizeDomain(domain.toLowerCase(), smtputf8);
1509
+ encodedDomain = normalizeDomain(domain, smtputf8);
1504
1510
  }
1505
1511
  catch (_err) {
1506
1512
  // keep domain as supplied
@@ -1,3 +1,3 @@
1
1
  export declare const name = "nodemailer";
2
- export declare const version = "10.4.0";
2
+ export declare const version = "10.4.1";
3
3
  export declare const homepage = "https://nodemailer.com/";
@@ -1,4 +1,4 @@
1
1
  // Generated by scripts/build.js from package.json. Do not edit by hand.
2
2
  export const name = 'nodemailer';
3
- export const version = '10.4.0';
3
+ export const version = '10.4.1';
4
4
  export const homepage = 'https://nodemailer.com/';
@@ -606,6 +606,13 @@ export const services = {
606
606
  "host": "mail.smtp2go.com",
607
607
  "port": 2525
608
608
  },
609
+ "SpacePost": {
610
+ "description": "SpacePost",
611
+ "host": "smtp.spacepost.dev",
612
+ "port": 25976,
613
+ "secure": false,
614
+ "requireTLS": true
615
+ },
609
616
  "Sparkpost": {
610
617
  "description": "SparkPost",
611
618
  "aliases": [
@@ -585,6 +585,14 @@
585
585
  "port": 2525
586
586
  },
587
587
 
588
+ "SpacePost": {
589
+ "description": "SpacePost",
590
+ "host": "smtp.spacepost.dev",
591
+ "port": 25976,
592
+ "secure": false,
593
+ "requireTLS": true
594
+ },
595
+
588
596
  "Sparkpost": {
589
597
  "description": "SparkPost",
590
598
  "aliases": ["SparkPost", "SparkPost Mail"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodemailer",
3
- "version": "10.4.0",
3
+ "version": "10.4.1",
4
4
  "description": "Easy as cake e-mail sending from your Node.js applications",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/nodemailer.js",
@@ -153,7 +153,7 @@
153
153
  },
154
154
  "homepage": "https://nodemailer.com/",
155
155
  "devDependencies": {
156
- "@aws-sdk/client-sesv2": "3.1161.0",
156
+ "@aws-sdk/client-sesv2": "3.1165.0",
157
157
  "@types/node": "20.19.43",
158
158
  "bunyan": "1.8.15",
159
159
  "c8": "12.0.0",
@@ -170,7 +170,7 @@
170
170
  "smtp-server": "3.21.3",
171
171
  "tsx": "4.23.15",
172
172
  "typescript": "6.0.3",
173
- "typescript-eslint": "8.72.1"
173
+ "typescript-eslint": "8.72.2"
174
174
  },
175
175
  "engines": {
176
176
  "node": ">=20.0.0"