@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.
Files changed (122) hide show
  1. package/.jsii +9 -9
  2. package/lib/rootmail.js +1 -1
  3. package/lib/ses-receive.js +1 -1
  4. package/node_modules/@aws-sdk/checksums/package.json +5 -5
  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 +8 -8
  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 +9 -9
  9. package/node_modules/@aws-sdk/client-s3/dist-cjs/index.js +1 -1
  10. package/node_modules/@aws-sdk/client-s3/package.json +12 -12
  11. package/node_modules/@aws-sdk/client-ses/dist-cjs/index.js +1 -1
  12. package/node_modules/@aws-sdk/client-ses/package.json +8 -8
  13. package/node_modules/@aws-sdk/client-ssm/dist-cjs/index.js +1 -1
  14. package/node_modules/@aws-sdk/client-ssm/package.json +8 -8
  15. package/node_modules/@aws-sdk/core/dist-cjs/submodules/client/index.js +7 -2
  16. package/node_modules/@aws-sdk/core/dist-cjs/submodules/httpAuthSchemes/index.js +3 -0
  17. package/node_modules/@aws-sdk/core/dist-es/submodules/client/setFeature.js +0 -2
  18. package/node_modules/@aws-sdk/core/dist-es/submodules/client/util-endpoints/lib/aws/partitions.js +6 -0
  19. package/node_modules/@aws-sdk/core/dist-es/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.js +3 -0
  20. package/node_modules/@aws-sdk/core/dist-types/submodules/client/util-endpoints/lib/aws/partitions.d.ts +20 -0
  21. package/node_modules/@aws-sdk/core/dist-types/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.d.ts +1 -0
  22. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/util-endpoints/lib/aws/partitions.d.ts +20 -0
  23. package/node_modules/@aws-sdk/core/package.json +7 -8
  24. package/node_modules/@aws-sdk/credential-provider-env/package.json +5 -5
  25. package/node_modules/@aws-sdk/credential-provider-http/package.json +7 -7
  26. package/node_modules/@aws-sdk/credential-provider-ini/package.json +12 -12
  27. package/node_modules/@aws-sdk/credential-provider-login/package.json +6 -6
  28. package/node_modules/@aws-sdk/credential-provider-node/package.json +10 -10
  29. package/node_modules/@aws-sdk/credential-provider-process/package.json +5 -5
  30. package/node_modules/@aws-sdk/credential-provider-sso/package.json +7 -7
  31. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +6 -6
  32. package/node_modules/@aws-sdk/middleware-sdk-route53/package.json +3 -3
  33. package/node_modules/@aws-sdk/middleware-sdk-s3/package.json +6 -6
  34. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
  35. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
  36. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
  37. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
  38. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
  39. package/node_modules/@aws-sdk/nested-clients/package.json +8 -8
  40. package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +3 -3
  41. package/node_modules/@aws-sdk/token-providers/package.json +6 -6
  42. package/node_modules/@aws-sdk/types/package.json +2 -2
  43. package/node_modules/@aws-sdk/xml-builder/package.json +2 -2
  44. package/node_modules/@smithy/core/dist-cjs/submodules/client/index.js +1 -0
  45. package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.browser.js +41 -13
  46. package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.js +41 -13
  47. package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/command.js +1 -0
  48. package/node_modules/@smithy/core/dist-es/submodules/retry/middleware-retry/retryMiddleware.js +11 -5
  49. package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/StandardRetryStrategy.js +2 -2
  50. package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/race.js +22 -0
  51. package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/retries-2026-config.js +6 -6
  52. package/node_modules/@smithy/core/dist-types/submodules/retry/util-retry/race.d.ts +3 -0
  53. package/node_modules/@smithy/core/dist-types/submodules/retry/util-retry/retries-2026-config.d.ts +16 -6
  54. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/retry/util-retry/race.d.ts +3 -0
  55. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/retry/util-retry/retries-2026-config.d.ts +16 -6
  56. package/node_modules/@smithy/core/package.json +2 -2
  57. package/node_modules/@smithy/fetch-http-handler/dist-cjs/index.js +10 -4
  58. package/node_modules/@smithy/fetch-http-handler/dist-es/fetch-http-handler.js +6 -2
  59. package/node_modules/@smithy/fetch-http-handler/dist-es/request-timeout.js +4 -2
  60. package/node_modules/@smithy/fetch-http-handler/dist-types/request-timeout.d.ts +12 -1
  61. package/node_modules/@smithy/fetch-http-handler/dist-types/ts3.4/request-timeout.d.ts +12 -1
  62. package/node_modules/@smithy/fetch-http-handler/package.json +3 -3
  63. package/node_modules/@smithy/node-http-handler/dist-cjs/index.js +31 -31
  64. package/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +2 -4
  65. package/node_modules/@smithy/node-http-handler/dist-es/set-socket-timeout.js +29 -27
  66. package/node_modules/@smithy/node-http-handler/dist-types/set-socket-timeout.d.ts +7 -3
  67. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/set-socket-timeout.d.ts +7 -3
  68. package/node_modules/@smithy/node-http-handler/package.json +3 -3
  69. package/node_modules/@smithy/types/dist-types/middleware.d.ts +6 -0
  70. package/node_modules/@smithy/types/dist-types/ts3.4/middleware.d.ts +6 -0
  71. package/node_modules/@smithy/types/package.json +1 -1
  72. package/node_modules/mailparser/CHANGELOG.md +7 -0
  73. package/node_modules/mailparser/package.json +3 -3
  74. package/node_modules/nodemailer/CHANGELOG.md +28 -0
  75. package/node_modules/nodemailer/README.md +21 -0
  76. package/node_modules/nodemailer/dist/cjs/addressparser/index.js +185 -2
  77. package/node_modules/nodemailer/dist/cjs/dkim/sign.js +2 -2
  78. package/node_modules/nodemailer/dist/cjs/errors.d.ts +2 -0
  79. package/node_modules/nodemailer/dist/cjs/errors.js +11 -1
  80. package/node_modules/nodemailer/dist/cjs/json-transport/index.js +2 -0
  81. package/node_modules/nodemailer/dist/cjs/mailer/index.d.ts +12 -2
  82. package/node_modules/nodemailer/dist/cjs/mailer/index.js +56 -4
  83. package/node_modules/nodemailer/dist/cjs/mailer/mail-message.d.ts +10 -0
  84. package/node_modules/nodemailer/dist/cjs/mime-funcs/index.d.ts +2 -1
  85. package/node_modules/nodemailer/dist/cjs/mime-funcs/index.js +72 -2
  86. package/node_modules/nodemailer/dist/cjs/mime-node/index.js +1 -73
  87. package/node_modules/nodemailer/dist/cjs/package-info.d.ts +1 -1
  88. package/node_modules/nodemailer/dist/cjs/package-info.js +1 -1
  89. package/node_modules/nodemailer/dist/cjs/shared/index.d.ts +23 -0
  90. package/node_modules/nodemailer/dist/cjs/shared/index.js +79 -0
  91. package/node_modules/nodemailer/dist/cjs/smtp-connection/index.js +6 -0
  92. package/node_modules/nodemailer/dist/cjs/smtp-pool/index.d.ts +10 -3
  93. package/node_modules/nodemailer/dist/cjs/smtp-pool/index.js +70 -12
  94. package/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.js +26 -4
  95. package/node_modules/nodemailer/dist/cjs/smtp-transport/index.d.ts +1 -0
  96. package/node_modules/nodemailer/dist/cjs/smtp-transport/index.js +47 -35
  97. package/node_modules/nodemailer/dist/cjs/well-known/services.js +7 -0
  98. package/node_modules/nodemailer/dist/esm/addressparser/index.js +185 -2
  99. package/node_modules/nodemailer/dist/esm/dkim/sign.js +2 -2
  100. package/node_modules/nodemailer/dist/esm/errors.d.ts +2 -0
  101. package/node_modules/nodemailer/dist/esm/errors.js +9 -0
  102. package/node_modules/nodemailer/dist/esm/json-transport/index.js +2 -0
  103. package/node_modules/nodemailer/dist/esm/mailer/index.d.ts +12 -2
  104. package/node_modules/nodemailer/dist/esm/mailer/index.js +56 -4
  105. package/node_modules/nodemailer/dist/esm/mailer/mail-message.d.ts +10 -0
  106. package/node_modules/nodemailer/dist/esm/mime-funcs/index.d.ts +2 -1
  107. package/node_modules/nodemailer/dist/esm/mime-funcs/index.js +72 -2
  108. package/node_modules/nodemailer/dist/esm/mime-node/index.js +1 -73
  109. package/node_modules/nodemailer/dist/esm/package-info.d.ts +1 -1
  110. package/node_modules/nodemailer/dist/esm/package-info.js +1 -1
  111. package/node_modules/nodemailer/dist/esm/shared/index.d.ts +23 -0
  112. package/node_modules/nodemailer/dist/esm/shared/index.js +78 -0
  113. package/node_modules/nodemailer/dist/esm/smtp-connection/index.js +6 -0
  114. package/node_modules/nodemailer/dist/esm/smtp-pool/index.d.ts +10 -3
  115. package/node_modules/nodemailer/dist/esm/smtp-pool/index.js +70 -12
  116. package/node_modules/nodemailer/dist/esm/smtp-pool/pool-resource.js +26 -4
  117. package/node_modules/nodemailer/dist/esm/smtp-transport/index.d.ts +1 -0
  118. package/node_modules/nodemailer/dist/esm/smtp-transport/index.js +47 -35
  119. package/node_modules/nodemailer/dist/esm/well-known/services.js +7 -0
  120. package/node_modules/nodemailer/dist/well-known/services.json +8 -0
  121. package/node_modules/nodemailer/package.json +7 -7
  122. package/package.json +10 -10
@@ -86,6 +86,7 @@ class PoolResource extends node_events_1.EventEmitter {
86
86
  }
87
87
  this._connection = false;
88
88
  this._connected = false;
89
+ this._closed = false;
89
90
  this.messages = 0;
90
91
  this.available = true;
91
92
  this._failed = false;
@@ -113,6 +114,10 @@ class PoolResource extends node_events_1.EventEmitter {
113
114
  // the proxy handshake, if any, counts against connectionTimeout as well
114
115
  const connectStartedAt = Date.now();
115
116
  this.pool.getSocket(Object.assign({}, this.options, { connectStartedAt }), (err, socketOptions) => {
117
+ if (this._closed) {
118
+ socketOptions && socketOptions.connection?.destroy();
119
+ return;
120
+ }
116
121
  if (err) {
117
122
  // nothing was connected, so no 'close' event is coming that would free the
118
123
  // slot this resource holds in the pool, report the failure the way a failed
@@ -136,7 +141,7 @@ class PoolResource extends node_events_1.EventEmitter {
136
141
  this.connection = new index_js_1.default(options);
137
142
  this.connection._connectStartedAt = connectStartedAt;
138
143
  this.connection.on('error', (err) => {
139
- if (this._sending) {
144
+ if (this._closed || this._sending) {
140
145
  // the send callback gets the same error and decides what it means for the message
141
146
  return;
142
147
  }
@@ -150,7 +155,7 @@ class PoolResource extends node_events_1.EventEmitter {
150
155
  return;
151
156
  }
152
157
  this._fail(err);
153
- if (returned) {
158
+ if (returned || this._closed) {
154
159
  return;
155
160
  }
156
161
  returned = true;
@@ -161,7 +166,7 @@ class PoolResource extends node_events_1.EventEmitter {
161
166
  returned = true;
162
167
  });
163
168
  this.connection.connect(err => {
164
- if (returned) {
169
+ if (returned || this._closed) {
165
170
  return;
166
171
  }
167
172
  if (err) {
@@ -172,7 +177,7 @@ class PoolResource extends node_events_1.EventEmitter {
172
177
  }
173
178
  if (this.auth && (this.connection.allowsAuth || options.forceAuth)) {
174
179
  this.connection.login(this.auth, err => {
175
- if (returned) {
180
+ if (returned || this._closed) {
176
181
  return;
177
182
  }
178
183
  returned = true;
@@ -200,6 +205,9 @@ class PoolResource extends node_events_1.EventEmitter {
200
205
  * @param callback Callback function
201
206
  */
202
207
  send(mail, callback) {
208
+ if (this._closed) {
209
+ return;
210
+ }
203
211
  if (!this._connected) {
204
212
  return this.connect(err => {
205
213
  if (err) {
@@ -231,6 +239,9 @@ class PoolResource extends node_events_1.EventEmitter {
231
239
  const reused = this.messages > 0;
232
240
  const messageStream = mail.message.createReadStream();
233
241
  this.connection.send(envelope, messageStream, (err, info) => {
242
+ if (mail.data.signal?.aborted) {
243
+ return;
244
+ }
234
245
  this._sending = false;
235
246
  this.messages++;
236
247
  if (err) {
@@ -277,6 +288,9 @@ class PoolResource extends node_events_1.EventEmitter {
277
288
  * @internal
278
289
  */
279
290
  _release() {
291
+ if (this._closed) {
292
+ return;
293
+ }
280
294
  if (this.messages >= this.options.maxMessages) {
281
295
  const err = new Error('Resource exhausted');
282
296
  err.code = errors.EMAXLIMIT;
@@ -285,6 +299,9 @@ class PoolResource extends node_events_1.EventEmitter {
285
299
  return;
286
300
  }
287
301
  this.pool._checkRateLimit(() => {
302
+ if (this._closed) {
303
+ return;
304
+ }
288
305
  this.available = true;
289
306
  this._startIdleTimer();
290
307
  this.emit('available');
@@ -327,6 +344,11 @@ class PoolResource extends node_events_1.EventEmitter {
327
344
  * Closes the connection
328
345
  */
329
346
  close() {
347
+ if (this._closed) {
348
+ return;
349
+ }
350
+ this._closed = true;
351
+ this.available = false;
330
352
  this._connected = false;
331
353
  this._stopIdleTimer();
332
354
  if (this.auth && this.auth.oauth2) {
@@ -93,6 +93,7 @@ export type SMTPTransportSendCallback = ResultCallback<SMTPSentMessageInfo>;
93
93
  * @param options Connection options
94
94
  */
95
95
  declare class SMTPTransport extends EventEmitter {
96
+ readonly supportsAbortSignal = true;
96
97
  options: SMTPTransportOptions;
97
98
  logger: shared.Logger;
98
99
  name: string;
@@ -59,6 +59,7 @@ const MESSAGE_AUTH_KEYS = ['type', 'user', 'pass', 'accessToken', 'refreshToken'
59
59
  class SMTPTransport extends node_events_1.EventEmitter {
60
60
  constructor(options) {
61
61
  super();
62
+ this.supportsAbortSignal = true;
62
63
  options = options || {};
63
64
  if (typeof options === 'string') {
64
65
  options = {
@@ -153,13 +154,46 @@ class SMTPTransport extends node_events_1.EventEmitter {
153
154
  * @param callback Callback function
154
155
  */
155
156
  send(mail, callback) {
157
+ const signal = mail.data.signal;
158
+ let returned = false;
159
+ let connection;
160
+ let perCallAuth;
161
+ const cleanupPerCallAuth = () => {
162
+ if (perCallAuth && perCallAuth !== this.auth && perCallAuth.oauth2) {
163
+ perCallAuth.oauth2.removeAllListeners();
164
+ }
165
+ perCallAuth = null;
166
+ };
167
+ const finish = (err, info) => {
168
+ if (returned) {
169
+ return;
170
+ }
171
+ returned = true;
172
+ signal?.removeEventListener('abort', onAbort);
173
+ cleanupPerCallAuth();
174
+ connection?.close();
175
+ callback(err, info);
176
+ };
177
+ function onAbort() {
178
+ finish(errors.createAbortError(signal));
179
+ }
180
+ if (signal) {
181
+ signal.addEventListener('abort', onAbort, { once: true });
182
+ if (signal.aborted) {
183
+ setImmediate(onAbort);
184
+ return;
185
+ }
186
+ }
156
187
  // the proxy handshake, if any, counts against connectionTimeout as well
157
188
  const connectStartedAt = Date.now();
158
189
  this.getSocket(Object.assign({}, this.options, { connectStartedAt }), (err, socketOptions) => {
190
+ if (returned) {
191
+ socketOptions && socketOptions.connection?.destroy();
192
+ return;
193
+ }
159
194
  if (err) {
160
- return callback(err);
195
+ return finish(err);
161
196
  }
162
- let returned = false;
163
197
  let options = this.options;
164
198
  if (socketOptions && socketOptions.connection) {
165
199
  this.logger.info({
@@ -173,24 +207,9 @@ class SMTPTransport extends node_events_1.EventEmitter {
173
207
  // only copy options if we need to modify it
174
208
  options = Object.assign(shared.assign(false, options), socketOptions);
175
209
  }
176
- const connection = new index_js_1.default(options);
177
- connection._connectStartedAt = connectStartedAt;
178
- let perCallAuth;
179
- const cleanupPerCallAuth = () => {
180
- if (perCallAuth && perCallAuth !== this.auth && perCallAuth.oauth2) {
181
- perCallAuth.oauth2.removeAllListeners();
182
- }
183
- perCallAuth = null;
184
- };
185
- connection.once('error', err => {
186
- if (returned) {
187
- return;
188
- }
189
- returned = true;
190
- cleanupPerCallAuth();
191
- connection.close();
192
- return callback(err);
193
- });
210
+ const smtp = (connection = new index_js_1.default(options));
211
+ smtp._connectStartedAt = connectStartedAt;
212
+ smtp.once('error', err => finish(err));
194
213
  const sendMessage = () => {
195
214
  const envelope = mail.message.getEnvelope();
196
215
  const messageId = mail.message.messageId();
@@ -209,20 +228,17 @@ class SMTPTransport extends node_events_1.EventEmitter {
209
228
  tnx: 'send',
210
229
  messageId
211
230
  }, 'Sending message %s to <%s>', messageId, recipients.join(', '));
212
- connection.send(envelope, mail.message.createReadStream(), (err, info) => {
231
+ smtp.send(envelope, mail.message.createReadStream(), (err, info) => {
213
232
  if (returned) {
214
233
  // the connection error handler has already reported this send
215
234
  return;
216
235
  }
217
- returned = true;
218
- cleanupPerCallAuth();
219
- connection.close();
220
236
  if (err) {
221
237
  this.logger.error({
222
238
  err,
223
239
  tnx: 'send'
224
240
  }, 'Send error for %s: %s', messageId, err.message);
225
- return callback(err);
241
+ return finish(err);
226
242
  }
227
243
  info.envelope = {
228
244
  from: envelope.from,
@@ -230,7 +246,7 @@ class SMTPTransport extends node_events_1.EventEmitter {
230
246
  };
231
247
  info.messageId = messageId;
232
248
  try {
233
- return callback(null, info);
249
+ return finish(null, info);
234
250
  }
235
251
  catch (E) {
236
252
  this.logger.error({
@@ -240,27 +256,23 @@ class SMTPTransport extends node_events_1.EventEmitter {
240
256
  }
241
257
  });
242
258
  };
243
- connection.connect(err => {
259
+ smtp.connect(err => {
244
260
  if (returned) {
245
261
  return;
246
262
  }
247
263
  if (err) {
248
264
  // the server closed the connection before the greeting
249
- returned = true;
250
- connection.close();
251
- return callback(err);
265
+ return finish(err);
252
266
  }
253
267
  perCallAuth = this.getAuth(mail.data.auth);
254
- if (perCallAuth && (connection.allowsAuth || options.forceAuth)) {
255
- connection.login(perCallAuth, err => {
268
+ if (perCallAuth && (smtp.allowsAuth || options.forceAuth)) {
269
+ smtp.login(perCallAuth, err => {
256
270
  cleanupPerCallAuth();
257
271
  if (returned) {
258
272
  return;
259
273
  }
260
274
  if (err) {
261
- returned = true;
262
- connection.close();
263
- return callback(err);
275
+ return finish(err);
264
276
  }
265
277
  sendMessage();
266
278
  });
@@ -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
@@ -1,4 +1,4 @@
1
- import * as punycode from '../punycode/index.js';
1
+ import * as shared from '../shared/index.js';
2
2
  import * as mimeFuncs from '../mime-funcs/index.js';
3
3
  import crypto from 'node:crypto';
4
4
  import * as errors from '../errors.js';
@@ -65,7 +65,7 @@ function generateDKIMHeader(domainName, keySelector, fieldNames, hashAlgo, bodyH
65
65
  'v=1',
66
66
  'a=rsa-' + hashAlgo,
67
67
  'c=relaxed/relaxed',
68
- 'd=' + punycode.toASCII(cleanTagValue(domainName)),
68
+ 'd=' + shared.normalizeDomain(cleanTagValue(domainName), false),
69
69
  'q=dns/txt',
70
70
  's=' + cleanTagValue(keySelector),
71
71
  'bh=' + bodyHash,
@@ -23,6 +23,7 @@ export declare const ERROR_CODES: {
23
23
  readonly EMESSAGE: "Message delivery error";
24
24
  readonly EOTP: "Invalid one-time passcode data (otp option)";
25
25
  readonly ESTREAM: "Stream processing error";
26
+ readonly EABORT: "Message sending aborted";
26
27
  readonly EAUTH: "Authentication failed";
27
28
  readonly ENOAUTH: "Authentication credentials not provided";
28
29
  readonly EOAUTH2: "OAuth2 token generation or refresh error";
@@ -51,6 +52,7 @@ export declare const EENVELOPE = "EENVELOPE";
51
52
  export declare const EMESSAGE = "EMESSAGE";
52
53
  export declare const EOTP = "EOTP";
53
54
  export declare const ESTREAM = "ESTREAM";
55
+ export declare const EABORT = "EABORT";
54
56
  export declare const EAUTH = "EAUTH";
55
57
  export declare const ENOAUTH = "ENOAUTH";
56
58
  export declare const EOAUTH2 = "EOAUTH2";
@@ -26,6 +26,7 @@ export const ERROR_CODES = {
26
26
  EMESSAGE: 'Message delivery error',
27
27
  EOTP: 'Invalid one-time passcode data (otp option)',
28
28
  ESTREAM: 'Stream processing error',
29
+ EABORT: 'Message sending aborted',
29
30
  // Authentication errors
30
31
  EAUTH: 'Authentication failed',
31
32
  ENOAUTH: 'Authentication credentials not provided',
@@ -55,6 +56,7 @@ export const EENVELOPE = 'EENVELOPE';
55
56
  export const EMESSAGE = 'EMESSAGE';
56
57
  export const EOTP = 'EOTP';
57
58
  export const ESTREAM = 'ESTREAM';
59
+ export const EABORT = 'EABORT';
58
60
  export const EAUTH = 'EAUTH';
59
61
  export const ENOAUTH = 'ENOAUTH';
60
62
  export const EOAUTH2 = 'EOAUTH2';
@@ -67,6 +69,13 @@ export const EPROXY = 'EPROXY';
67
69
  export const EFILEACCESS = 'EFILEACCESS';
68
70
  export const EURLACCESS = 'EURLACCESS';
69
71
  export const EFETCH = 'EFETCH';
72
+ /** Creates the error reported when a caller cancels an individual send. @internal */
73
+ export const createAbortError = (signal) => {
74
+ const err = new Error('Message sending aborted', { cause: signal.reason });
75
+ err.name = 'AbortError';
76
+ err.code = EABORT;
77
+ return err;
78
+ };
70
79
  /**
71
80
  * Tells whether the error ended the connection rather than rejected what was sent over it
72
81
  */
@@ -48,6 +48,8 @@ class JSONTransport {
48
48
  }
49
49
  delete data.envelope;
50
50
  delete data.normalizedHeaders;
51
+ // the per-message AbortSignal is not message data
52
+ delete data.signal;
51
53
  // the message field is the object itself with skipEncoding, the
52
54
  // createTransport overload for that option types the result accordingly
53
55
  return done(null, {
@@ -112,6 +112,11 @@ export interface MailMeta {
112
112
  * declared on Transport, Transporter and Mail
113
113
  */
114
114
  export interface Transport<T = SentMessageInfo, D extends TransportOptions = TransportOptions> {
115
+ /**
116
+ * Set only if send() cancels its own work on mail.data.signal and removes its signal listener
117
+ * when finished. Without it the signal is still honored up to dispatch, then ignored.
118
+ */
119
+ supportsAbortSignal?: boolean | undefined;
115
120
  /** Transport name, used for logging */
116
121
  name: string;
117
122
  /** Transport version, used for logging */
@@ -176,8 +181,13 @@ declare class Mail<out T = SentMessageInfo, out D extends TransportOptions = Tra
176
181
  dkim: DKIM | false;
177
182
  transporter: Transport<T, D>;
178
183
  logger: shared.Logger;
179
- /** 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 */