@mavogel/awscdk-rootmail 0.1.42 → 0.1.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +8 -8
- package/lib/rootmail.js +1 -1
- package/lib/ses-receive.js +1 -1
- package/node_modules/@aws-sdk/checksums/package.json +3 -3
- package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-cloudwatch-logs/package.json +4 -4
- package/node_modules/@aws-sdk/client-route-53/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-route-53/package.json +4 -4
- package/node_modules/@aws-sdk/client-s3/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-s3/package.json +7 -7
- package/node_modules/@aws-sdk/client-ses/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-ses/package.json +4 -4
- package/node_modules/@aws-sdk/client-ssm/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-ssm/package.json +4 -4
- package/node_modules/@aws-sdk/core/dist-cjs/submodules/client/index.js +1 -2
- package/node_modules/@aws-sdk/core/dist-es/submodules/client/setFeature.js +0 -2
- package/node_modules/@aws-sdk/core/package.json +4 -5
- package/node_modules/@aws-sdk/credential-provider-env/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-http/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +10 -10
- package/node_modules/@aws-sdk/credential-provider-login/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-node/package.json +8 -8
- package/node_modules/@aws-sdk/credential-provider-process/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-sdk-s3/package.json +3 -3
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/package.json +3 -3
- package/node_modules/@aws-sdk/token-providers/package.json +4 -4
- package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.browser.js +8 -8
- package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.js +8 -8
- package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/StandardRetryStrategy.js +2 -2
- package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/retries-2026-config.js +6 -6
- package/node_modules/@smithy/core/dist-types/submodules/retry/util-retry/retries-2026-config.d.ts +16 -6
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/retry/util-retry/retries-2026-config.d.ts +16 -6
- package/node_modules/@smithy/core/package.json +1 -1
- package/node_modules/mailparser/CHANGELOG.md +7 -0
- package/node_modules/mailparser/package.json +3 -3
- package/node_modules/nodemailer/CHANGELOG.md +28 -0
- package/node_modules/nodemailer/README.md +21 -0
- package/node_modules/nodemailer/dist/cjs/addressparser/index.js +185 -2
- package/node_modules/nodemailer/dist/cjs/dkim/sign.js +2 -2
- package/node_modules/nodemailer/dist/cjs/errors.d.ts +2 -0
- package/node_modules/nodemailer/dist/cjs/errors.js +11 -1
- package/node_modules/nodemailer/dist/cjs/json-transport/index.js +2 -0
- package/node_modules/nodemailer/dist/cjs/mailer/index.d.ts +12 -2
- package/node_modules/nodemailer/dist/cjs/mailer/index.js +56 -4
- package/node_modules/nodemailer/dist/cjs/mailer/mail-message.d.ts +10 -0
- package/node_modules/nodemailer/dist/cjs/mime-funcs/index.d.ts +2 -1
- package/node_modules/nodemailer/dist/cjs/mime-funcs/index.js +72 -2
- package/node_modules/nodemailer/dist/cjs/mime-node/index.js +1 -73
- package/node_modules/nodemailer/dist/cjs/package-info.d.ts +1 -1
- package/node_modules/nodemailer/dist/cjs/package-info.js +1 -1
- package/node_modules/nodemailer/dist/cjs/shared/index.d.ts +23 -0
- package/node_modules/nodemailer/dist/cjs/shared/index.js +79 -0
- package/node_modules/nodemailer/dist/cjs/smtp-connection/index.js +6 -0
- package/node_modules/nodemailer/dist/cjs/smtp-pool/index.d.ts +10 -3
- package/node_modules/nodemailer/dist/cjs/smtp-pool/index.js +70 -12
- package/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.js +26 -4
- package/node_modules/nodemailer/dist/cjs/smtp-transport/index.d.ts +1 -0
- package/node_modules/nodemailer/dist/cjs/smtp-transport/index.js +47 -35
- package/node_modules/nodemailer/dist/cjs/well-known/services.js +7 -0
- package/node_modules/nodemailer/dist/esm/addressparser/index.js +185 -2
- package/node_modules/nodemailer/dist/esm/dkim/sign.js +2 -2
- package/node_modules/nodemailer/dist/esm/errors.d.ts +2 -0
- package/node_modules/nodemailer/dist/esm/errors.js +9 -0
- package/node_modules/nodemailer/dist/esm/json-transport/index.js +2 -0
- package/node_modules/nodemailer/dist/esm/mailer/index.d.ts +12 -2
- package/node_modules/nodemailer/dist/esm/mailer/index.js +56 -4
- package/node_modules/nodemailer/dist/esm/mailer/mail-message.d.ts +10 -0
- package/node_modules/nodemailer/dist/esm/mime-funcs/index.d.ts +2 -1
- package/node_modules/nodemailer/dist/esm/mime-funcs/index.js +72 -2
- package/node_modules/nodemailer/dist/esm/mime-node/index.js +1 -73
- package/node_modules/nodemailer/dist/esm/package-info.d.ts +1 -1
- package/node_modules/nodemailer/dist/esm/package-info.js +1 -1
- package/node_modules/nodemailer/dist/esm/shared/index.d.ts +23 -0
- package/node_modules/nodemailer/dist/esm/shared/index.js +78 -0
- package/node_modules/nodemailer/dist/esm/smtp-connection/index.js +6 -0
- package/node_modules/nodemailer/dist/esm/smtp-pool/index.d.ts +10 -3
- package/node_modules/nodemailer/dist/esm/smtp-pool/index.js +70 -12
- package/node_modules/nodemailer/dist/esm/smtp-pool/pool-resource.js +26 -4
- package/node_modules/nodemailer/dist/esm/smtp-transport/index.d.ts +1 -0
- package/node_modules/nodemailer/dist/esm/smtp-transport/index.js +47 -35
- package/node_modules/nodemailer/dist/esm/well-known/services.js +7 -0
- package/node_modules/nodemailer/dist/well-known/services.json +8 -0
- package/node_modules/nodemailer/package.json +7 -7
- package/package.json +7 -7
|
@@ -56,6 +56,7 @@ const REQUEUE_MAX_DELAY = 2000;
|
|
|
56
56
|
class SMTPPool extends node_events_1.EventEmitter {
|
|
57
57
|
constructor(options) {
|
|
58
58
|
super();
|
|
59
|
+
this.supportsAbortSignal = true;
|
|
59
60
|
options = options || {};
|
|
60
61
|
if (typeof options === 'string') {
|
|
61
62
|
options = {
|
|
@@ -134,20 +135,33 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
134
135
|
return false;
|
|
135
136
|
}
|
|
136
137
|
// counted until the callback runs, whichever path runs it: delivered, failed, requeued
|
|
137
|
-
// until it gives up, or drained by close()
|
|
138
|
+
// until it gives up, aborted, or drained by close()
|
|
138
139
|
let counted = true;
|
|
140
|
+
let detachSignal;
|
|
139
141
|
this._pending++;
|
|
140
|
-
|
|
142
|
+
const entry = {
|
|
141
143
|
mail,
|
|
142
144
|
requeueAttempts: 0,
|
|
143
145
|
callback: (err, info) => {
|
|
144
|
-
if (counted) {
|
|
145
|
-
|
|
146
|
-
this._pending--;
|
|
146
|
+
if (!counted) {
|
|
147
|
+
return;
|
|
147
148
|
}
|
|
149
|
+
counted = false;
|
|
150
|
+
this._pending--;
|
|
151
|
+
detachSignal?.();
|
|
152
|
+
entry.resource = undefined;
|
|
148
153
|
callback(err, info);
|
|
149
154
|
}
|
|
150
|
-
}
|
|
155
|
+
};
|
|
156
|
+
this._queue.push(entry);
|
|
157
|
+
const signal = mail.data.signal;
|
|
158
|
+
if (signal) {
|
|
159
|
+
// one listener for the original entry, retained across connection-close retries
|
|
160
|
+
detachSignal = this._watchAbortSignal(entry, signal, () => counted);
|
|
161
|
+
if (signal.aborted) {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
151
165
|
if (this.idling && this._queue.length >= this.options.maxConnections) {
|
|
152
166
|
this.idling = false;
|
|
153
167
|
}
|
|
@@ -155,10 +169,49 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
155
169
|
return true;
|
|
156
170
|
}
|
|
157
171
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
172
|
+
* Fails a queued or assigned entry when its signal aborts: removes it from the queue, or
|
|
173
|
+
* closes the connection delivering it, so other deliveries in the pool can continue.
|
|
174
|
+
* Returns a function that removes the listener.
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
_watchAbortSignal(entry, signal, isPending) {
|
|
178
|
+
const onAbort = () => {
|
|
179
|
+
if (!isPending()) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const index = this._queue.indexOf(entry);
|
|
183
|
+
if (index !== -1) {
|
|
184
|
+
this._queue.splice(index, 1);
|
|
185
|
+
}
|
|
186
|
+
const resource = entry.resource;
|
|
187
|
+
if (resource && resource.queueEntry === entry) {
|
|
188
|
+
// Detach before closing: the close handler must not retry this message.
|
|
189
|
+
resource.queueEntry = false;
|
|
190
|
+
resource.close();
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
entry.callback(errors.createAbortError(signal));
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
// Removing a queued entry can make the pool idle again.
|
|
197
|
+
setImmediate(() => this._processMessages());
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
201
|
+
if (signal.aborted) {
|
|
202
|
+
setImmediate(onAbort);
|
|
203
|
+
}
|
|
204
|
+
return () => signal.removeEventListener('abort', onAbort);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Closes the pool. Idle connections are closed at once and a connection in the middle of a
|
|
208
|
+
* delivery finishes it first, unless `force` is set: then it is closed too and its message
|
|
209
|
+
* fails. `force` is for a caller that has given up on a delivery, such as one a server is
|
|
210
|
+
* stalling by trickling its replies, which no socket timeout notices.
|
|
211
|
+
*
|
|
212
|
+
* @param options.force - Also close connections that are delivering a message
|
|
160
213
|
*/
|
|
161
|
-
close() {
|
|
214
|
+
close(options) {
|
|
162
215
|
let connection;
|
|
163
216
|
const len = this._connections.length;
|
|
164
217
|
this._closed = true;
|
|
@@ -169,9 +222,10 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
169
222
|
if (!len && !this._queue.length) {
|
|
170
223
|
return;
|
|
171
224
|
}
|
|
172
|
-
// remove all available connections
|
|
225
|
+
// remove all available connections, and with `force` the busy ones too
|
|
226
|
+
const force = !!options?.force;
|
|
173
227
|
for (let i = len - 1; i >= 0; i--) {
|
|
174
|
-
if (this._connections[i] && this._connections[i].available) {
|
|
228
|
+
if (this._connections[i] && (force || this._connections[i].available)) {
|
|
175
229
|
connection = this._connections[i];
|
|
176
230
|
connection.close();
|
|
177
231
|
this.logger.info({
|
|
@@ -249,6 +303,7 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
249
303
|
this.emit('idle');
|
|
250
304
|
}
|
|
251
305
|
const entry = (connection.queueEntry = this._queue.shift());
|
|
306
|
+
entry.resource = connection;
|
|
252
307
|
entry.messageId = (connection.queueEntry.mail.message.getHeader('message-id') || '').replace(/[<>\s]/g, '');
|
|
253
308
|
connection.available = false;
|
|
254
309
|
this.logger.debug({
|
|
@@ -356,7 +411,9 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
356
411
|
setTimeout(() => {
|
|
357
412
|
let delay = 0;
|
|
358
413
|
if (connection.queueEntry) {
|
|
359
|
-
|
|
414
|
+
// a closed pool (a forced close ends a delivery on purpose) fails the
|
|
415
|
+
// message rather than queueing it for a retry that would never run
|
|
416
|
+
if (!this._closed && this._shouldRequeuOnConnectionClose(connection.queueEntry)) {
|
|
360
417
|
delay = this._requeueEntryOnConnectionClose(connection);
|
|
361
418
|
}
|
|
362
419
|
else {
|
|
@@ -418,6 +475,7 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
418
475
|
messageId: connection.queueEntry.messageId,
|
|
419
476
|
action: 'requeue'
|
|
420
477
|
}, 'Re-queued message <%s> for #%s. Attempt: #%s', connection.queueEntry.messageId, connection.id, connection.queueEntry.requeueAttempts);
|
|
478
|
+
connection.queueEntry.resource = undefined;
|
|
421
479
|
this._queue.unshift(connection.queueEntry);
|
|
422
480
|
connection.queueEntry = false;
|
|
423
481
|
return delay;
|
|
@@ -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
|
|
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
|
-
|
|
178
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
250
|
-
connection.close();
|
|
251
|
-
return callback(err);
|
|
265
|
+
return finish(err);
|
|
252
266
|
}
|
|
253
267
|
perCallAuth = this.getAuth(mail.data.auth);
|
|
254
|
-
if (perCallAuth && (
|
|
255
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|