nodemailer 10.4.0 → 10.5.0
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 +21 -0
- package/README.md +21 -0
- package/dist/cjs/addressparser/index.js +185 -2
- package/dist/cjs/dkim/sign.js +2 -2
- package/dist/cjs/errors.d.ts +2 -0
- package/dist/cjs/errors.js +11 -1
- package/dist/cjs/json-transport/index.js +2 -0
- package/dist/cjs/mailer/index.d.ts +5 -0
- package/dist/cjs/mailer/index.js +56 -4
- package/dist/cjs/mailer/mail-message.d.ts +10 -0
- package/dist/cjs/mime-funcs/index.d.ts +2 -1
- package/dist/cjs/mime-funcs/index.js +72 -2
- package/dist/cjs/mime-node/index.js +1 -73
- package/dist/cjs/package-info.d.ts +1 -1
- package/dist/cjs/package-info.js +1 -1
- package/dist/cjs/shared/index.d.ts +23 -0
- package/dist/cjs/shared/index.js +79 -0
- package/dist/cjs/smtp-connection/index.js +6 -0
- package/dist/cjs/smtp-pool/index.d.ts +1 -0
- package/dist/cjs/smtp-pool/index.js +57 -6
- package/dist/cjs/smtp-pool/pool-resource.js +26 -4
- package/dist/cjs/smtp-transport/index.d.ts +1 -0
- package/dist/cjs/smtp-transport/index.js +47 -35
- package/dist/cjs/well-known/services.js +7 -0
- package/dist/esm/addressparser/index.js +185 -2
- package/dist/esm/dkim/sign.js +2 -2
- package/dist/esm/errors.d.ts +2 -0
- package/dist/esm/errors.js +9 -0
- package/dist/esm/json-transport/index.js +2 -0
- package/dist/esm/mailer/index.d.ts +5 -0
- package/dist/esm/mailer/index.js +56 -4
- package/dist/esm/mailer/mail-message.d.ts +10 -0
- package/dist/esm/mime-funcs/index.d.ts +2 -1
- package/dist/esm/mime-funcs/index.js +72 -2
- package/dist/esm/mime-node/index.js +1 -73
- package/dist/esm/package-info.d.ts +1 -1
- package/dist/esm/package-info.js +1 -1
- package/dist/esm/shared/index.d.ts +23 -0
- package/dist/esm/shared/index.js +78 -0
- package/dist/esm/smtp-connection/index.js +6 -0
- package/dist/esm/smtp-pool/index.d.ts +1 -0
- package/dist/esm/smtp-pool/index.js +57 -6
- package/dist/esm/smtp-pool/pool-resource.js +26 -4
- package/dist/esm/smtp-transport/index.d.ts +1 -0
- package/dist/esm/smtp-transport/index.js +47 -35
- package/dist/esm/well-known/services.js +7 -0
- package/dist/well-known/services.json +8 -0
- package/package.json +3 -3
|
@@ -39,10 +39,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
41
41
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
42
|
-
const punycode = __importStar(require("../punycode/index.js"));
|
|
43
42
|
const node_stream_1 = require("node:stream");
|
|
44
43
|
const shared = __importStar(require("../shared/index.js"));
|
|
45
|
-
const node_url_1 = __importDefault(require("node:url"));
|
|
46
44
|
const mimeFuncs = __importStar(require("../mime-funcs/index.js"));
|
|
47
45
|
const qp = __importStar(require("../qp/index.js"));
|
|
48
46
|
const base64 = __importStar(require("../base64/index.js"));
|
|
@@ -93,20 +91,6 @@ function stripWhitespaceInAngleBrackets(value) {
|
|
|
93
91
|
}
|
|
94
92
|
return result + value.slice(pos);
|
|
95
93
|
}
|
|
96
|
-
// domainToASCII and domainToUnicode are WHATWG host parsers rather than plain IDNA
|
|
97
|
-
// mappers, so they do more than map: they cut the host at '/', '\\', '?' and '#', drop C0
|
|
98
|
-
// controls, and percent-decode. Handing them 'evil.example/mail.corp.example' returns the
|
|
99
|
-
// deliverable 'evil.example', which would turn a value the bundled codec leaves as
|
|
100
|
-
// unroutable garbage into mail for a domain the sender never named. None of these
|
|
101
|
-
// characters are legal in a domain, so keep them away from the mapper.
|
|
102
|
-
const URL_PARSER_UNSAFE = /[/\\?#%\x00-\x20\x7F]/;
|
|
103
|
-
// RFC 1035 bounds a label at 63 octets and a domain at 253. An A-label is never shorter than
|
|
104
|
-
// the code points it encodes, so anything past these bounds could not have become a valid
|
|
105
|
-
// domain whichever way it is encoded. The bundled codec is super-linear in the length of a
|
|
106
|
-
// label, a 60 KB label of distinct code points took seconds to encode, several times per
|
|
107
|
-
// address, so it is only handed what could be a domain
|
|
108
|
-
const MAX_DOMAIN_LENGTH = 253;
|
|
109
|
-
const MAX_LABEL_LENGTH = 63;
|
|
110
94
|
// pipeline() needs a callback to not throw, the errors it sees reach the last stream anyway
|
|
111
95
|
const PIPELINE_NOOP = () => false;
|
|
112
96
|
// The error a node streaming into an output that was destroyed stops with
|
|
@@ -115,62 +99,6 @@ function abortedError() {
|
|
|
115
99
|
err.code = errors.ESTREAM;
|
|
116
100
|
return err;
|
|
117
101
|
}
|
|
118
|
-
/**
|
|
119
|
-
* Checks a domain against the DNS length limits, counted in code points per label and in
|
|
120
|
-
* total. The label separators are the ones the bundled codec splits on.
|
|
121
|
-
*
|
|
122
|
-
* @param domain Domain to check
|
|
123
|
-
* @return true if a label or the domain as a whole is too long to be a valid domain
|
|
124
|
-
*/
|
|
125
|
-
function exceedsDomainLimits(domain) {
|
|
126
|
-
let total = 0;
|
|
127
|
-
let label = 0;
|
|
128
|
-
for (const char of domain) {
|
|
129
|
-
total++;
|
|
130
|
-
if (char === '.' || char === '。' || char === '.' || char === '。') {
|
|
131
|
-
label = 0;
|
|
132
|
-
}
|
|
133
|
-
else if (++label > MAX_LABEL_LENGTH) {
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return total > MAX_DOMAIN_LENGTH;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Encodes a domain the way browsers, the WHATWG URL Standard and DNS facing resolvers do,
|
|
141
|
-
* which is with UTS-46 mapping applied before the Punycode step.
|
|
142
|
-
*
|
|
143
|
-
* The bundled codec is plain RFC 3492 and maps nothing, so it disagrees with every
|
|
144
|
-
* conformant parser on any domain holding a mapped or ignored code point. An invisible
|
|
145
|
-
* U+00AD in 'compa\u00ADny.com' encoded to 'xn--company-pka.com' where a validator reads
|
|
146
|
-
* 'company.com', which let an allow-listed domain be checked and a different one mailed.
|
|
147
|
-
*
|
|
148
|
-
* Anything the URL parser does not accept as a hostname, an address literal such as
|
|
149
|
-
* '[127.0.0.1]' included, comes back empty and falls through to the bundled codec, which
|
|
150
|
-
* leaves those as they were supplied.
|
|
151
|
-
*
|
|
152
|
-
* @param domain Domain to encode, already lowercased by the caller
|
|
153
|
-
* @param toUnicode Return the U-label form instead of the A-label form
|
|
154
|
-
* @return Encoded domain
|
|
155
|
-
*/
|
|
156
|
-
function normalizeDomain(domain, toUnicode) {
|
|
157
|
-
// domainToASCII and domainToUnicode landed in Node 7, the bundled codec covers Node 6
|
|
158
|
-
if (typeof node_url_1.default.domainToASCII === 'function' && typeof node_url_1.default.domainToUnicode === 'function' && !URL_PARSER_UNSAFE.test(domain)) {
|
|
159
|
-
// The U-label form is decoded from the A-label form rather than from the input:
|
|
160
|
-
// Deno's domainToASCII returns an empty string for a label it cannot decode, while
|
|
161
|
-
// its domainToUnicode returns the label with U+FFFD in place of the bad part
|
|
162
|
-
const ascii = node_url_1.default.domainToASCII(domain);
|
|
163
|
-
const mapped = ascii && toUnicode ? node_url_1.default.domainToUnicode(ascii) : ascii;
|
|
164
|
-
if (mapped) {
|
|
165
|
-
return mapped;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (exceedsDomainLimits(domain)) {
|
|
169
|
-
// too long to be a domain whichever way it is encoded, keep it as supplied
|
|
170
|
-
return domain;
|
|
171
|
-
}
|
|
172
|
-
return toUnicode ? punycode.toUnicode(domain) : punycode.toASCII(domain);
|
|
173
|
-
}
|
|
174
102
|
/**
|
|
175
103
|
* Removes the characters that must never reach a multipart delimiter line.
|
|
176
104
|
*
|
|
@@ -1538,7 +1466,7 @@ class MimeNode {
|
|
|
1538
1466
|
// symmetry on both sides of the '@' rather than being encoded to an A-label
|
|
1539
1467
|
const smtputf8 = /[\x80-\uFFFF]/.test(user);
|
|
1540
1468
|
try {
|
|
1541
|
-
encodedDomain = normalizeDomain(domain
|
|
1469
|
+
encodedDomain = shared.normalizeDomain(domain, smtputf8);
|
|
1542
1470
|
}
|
|
1543
1471
|
catch (_err) {
|
|
1544
1472
|
// keep domain as supplied
|
package/dist/cjs/package-info.js
CHANGED
|
@@ -289,3 +289,26 @@ export declare function unreadableStreamError(stream: Readable): NodemailerError
|
|
|
289
289
|
* @param callback Callback function with (err, value)
|
|
290
290
|
*/
|
|
291
291
|
export declare function resolveStream(stream: Readable, callback: (err: Error | null, value?: Buffer) => void): void;
|
|
292
|
+
/**
|
|
293
|
+
* Encodes a domain the way browsers, the WHATWG URL Standard and DNS facing resolvers do,
|
|
294
|
+
* which is with UTS-46 mapping applied before the Punycode step.
|
|
295
|
+
*
|
|
296
|
+
* The bundled codec is plain RFC 3492 and maps nothing, so it disagrees with every
|
|
297
|
+
* conformant parser on any domain holding a mapped or ignored code point. An invisible
|
|
298
|
+
* U+00AD in 'compa\u00ADny.com' encoded to 'xn--company-pka.com' where a validator reads
|
|
299
|
+
* 'company.com', which let an allow-listed domain be checked and a different one mailed.
|
|
300
|
+
*
|
|
301
|
+
* Anything the URL parser does not accept as a hostname, an address literal such as
|
|
302
|
+
* '[127.0.0.1]' included, comes back empty and falls through to the bundled codec, which
|
|
303
|
+
* leaves those as they were supplied apart from lowercasing them.
|
|
304
|
+
*
|
|
305
|
+
* The mapper gets the domain as supplied, since UTS-46 does its own case mapping and
|
|
306
|
+
* toLowerCase() differs from it: it turns U+1E9E into U+00DF where Node 20 and 22 map it
|
|
307
|
+
* to 'ss', and a word-final U+03A3 into U+03C2 where UTS-46 gives U+03C3. Lowercasing
|
|
308
|
+
* first sent 'user@stra\u1E9Ee.de', which a validator reads as strasse.de, to xn--strae-oqa.de.
|
|
309
|
+
*
|
|
310
|
+
* @param domain Domain to encode
|
|
311
|
+
* @param toUnicode Return the U-label form instead of the A-label form
|
|
312
|
+
* @return Encoded domain
|
|
313
|
+
*/
|
|
314
|
+
export declare function normalizeDomain(domain: string, toUnicode: boolean): string;
|
package/dist/cjs/shared/index.js
CHANGED
|
@@ -43,6 +43,7 @@ exports.recordStreamErrors = recordStreamErrors;
|
|
|
43
43
|
exports.destroyStream = destroyStream;
|
|
44
44
|
exports.unreadableStreamError = unreadableStreamError;
|
|
45
45
|
exports.resolveStream = resolveStream;
|
|
46
|
+
exports.normalizeDomain = normalizeDomain;
|
|
46
47
|
const urllib = __importStar(require("./url.js"));
|
|
47
48
|
const node_util_1 = __importDefault(require("node:util"));
|
|
48
49
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
@@ -54,6 +55,8 @@ Object.defineProperty(exports, "copyOwnKeys", { enumerable: true, get: function
|
|
|
54
55
|
const node_dns_1 = __importDefault(require("node:dns"));
|
|
55
56
|
const node_net_1 = __importDefault(require("node:net"));
|
|
56
57
|
const node_os_1 = __importDefault(require("node:os"));
|
|
58
|
+
const node_url_1 = __importDefault(require("node:url"));
|
|
59
|
+
const punycode = __importStar(require("../punycode/index.js"));
|
|
57
60
|
const node_stream_1 = require("node:stream");
|
|
58
61
|
const DNS_TTL = 5 * 60 * 1000;
|
|
59
62
|
const CACHE_CLEANUP_INTERVAL = 30 * 1000; // Minimum 30 seconds between cleanups
|
|
@@ -771,3 +774,79 @@ function createDefaultLogger(levels) {
|
|
|
771
774
|
});
|
|
772
775
|
return logger;
|
|
773
776
|
}
|
|
777
|
+
// domainToASCII and domainToUnicode are WHATWG host parsers rather than plain IDNA
|
|
778
|
+
// mappers, so they do more than map: they cut the host at '/', '\\', '?' and '#', drop C0
|
|
779
|
+
// controls, and percent-decode. Handing them 'evil.example/mail.corp.example' returns the
|
|
780
|
+
// deliverable 'evil.example', which would turn a value the bundled codec leaves as
|
|
781
|
+
// unroutable garbage into mail for a domain the sender never named. None of these
|
|
782
|
+
// characters are legal in a domain, so keep them away from the mapper.
|
|
783
|
+
const URL_PARSER_UNSAFE = /[/\\?#%\x00-\x20\x7F]/;
|
|
784
|
+
// RFC 1035 bounds a label at 63 octets and a domain at 253. An A-label is never shorter than
|
|
785
|
+
// the code points it encodes, so anything past these bounds could not have become a valid
|
|
786
|
+
// domain whichever way it is encoded. The bundled codec is super-linear in the length of a
|
|
787
|
+
// label, a 60 KB label of distinct code points took seconds to encode, several times per
|
|
788
|
+
// address, so it is only handed what could be a domain
|
|
789
|
+
const MAX_DOMAIN_LENGTH = 253;
|
|
790
|
+
const MAX_LABEL_LENGTH = 63;
|
|
791
|
+
/**
|
|
792
|
+
* Checks a domain against the DNS length limits, counted in code points per label and in
|
|
793
|
+
* total. The label separators are the ones the bundled codec splits on.
|
|
794
|
+
*
|
|
795
|
+
* @param domain Domain to check
|
|
796
|
+
* @return true if a label or the domain as a whole is too long to be a valid domain
|
|
797
|
+
*/
|
|
798
|
+
function exceedsDomainLimits(domain) {
|
|
799
|
+
let total = 0;
|
|
800
|
+
let label = 0;
|
|
801
|
+
for (const char of domain) {
|
|
802
|
+
total++;
|
|
803
|
+
if (char === '.' || char === '。' || char === '.' || char === '。') {
|
|
804
|
+
label = 0;
|
|
805
|
+
}
|
|
806
|
+
else if (++label > MAX_LABEL_LENGTH) {
|
|
807
|
+
return true;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return total > MAX_DOMAIN_LENGTH;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Encodes a domain the way browsers, the WHATWG URL Standard and DNS facing resolvers do,
|
|
814
|
+
* which is with UTS-46 mapping applied before the Punycode step.
|
|
815
|
+
*
|
|
816
|
+
* The bundled codec is plain RFC 3492 and maps nothing, so it disagrees with every
|
|
817
|
+
* conformant parser on any domain holding a mapped or ignored code point. An invisible
|
|
818
|
+
* U+00AD in 'compa\u00ADny.com' encoded to 'xn--company-pka.com' where a validator reads
|
|
819
|
+
* 'company.com', which let an allow-listed domain be checked and a different one mailed.
|
|
820
|
+
*
|
|
821
|
+
* Anything the URL parser does not accept as a hostname, an address literal such as
|
|
822
|
+
* '[127.0.0.1]' included, comes back empty and falls through to the bundled codec, which
|
|
823
|
+
* leaves those as they were supplied apart from lowercasing them.
|
|
824
|
+
*
|
|
825
|
+
* The mapper gets the domain as supplied, since UTS-46 does its own case mapping and
|
|
826
|
+
* toLowerCase() differs from it: it turns U+1E9E into U+00DF where Node 20 and 22 map it
|
|
827
|
+
* to 'ss', and a word-final U+03A3 into U+03C2 where UTS-46 gives U+03C3. Lowercasing
|
|
828
|
+
* first sent 'user@stra\u1E9Ee.de', which a validator reads as strasse.de, to xn--strae-oqa.de.
|
|
829
|
+
*
|
|
830
|
+
* @param domain Domain to encode
|
|
831
|
+
* @param toUnicode Return the U-label form instead of the A-label form
|
|
832
|
+
* @return Encoded domain
|
|
833
|
+
*/
|
|
834
|
+
function normalizeDomain(domain, toUnicode) {
|
|
835
|
+
// domainToASCII and domainToUnicode landed in Node 7, the bundled codec covers Node 6
|
|
836
|
+
if (typeof node_url_1.default.domainToASCII === 'function' && typeof node_url_1.default.domainToUnicode === 'function' && !URL_PARSER_UNSAFE.test(domain)) {
|
|
837
|
+
// The U-label form is decoded from the A-label form rather than from the input:
|
|
838
|
+
// Deno's domainToASCII returns an empty string for a label it cannot decode, while
|
|
839
|
+
// its domainToUnicode returns the label with U+FFFD in place of the bad part
|
|
840
|
+
const ascii = node_url_1.default.domainToASCII(domain);
|
|
841
|
+
const mapped = ascii && toUnicode ? node_url_1.default.domainToUnicode(ascii) : ascii;
|
|
842
|
+
if (mapped) {
|
|
843
|
+
return mapped;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
domain = domain.toLowerCase();
|
|
847
|
+
if (exceedsDomainLimits(domain)) {
|
|
848
|
+
// too long to be a domain whichever way it is encoded, keep it as supplied
|
|
849
|
+
return domain;
|
|
850
|
+
}
|
|
851
|
+
return toUnicode ? punycode.toUnicode(domain) : punycode.toASCII(domain);
|
|
852
|
+
}
|
|
@@ -287,6 +287,9 @@ class SMTPConnection extends node_events_1.EventEmitter {
|
|
|
287
287
|
// socket object is set up but not yet connected
|
|
288
288
|
this._socket = this.options.socket;
|
|
289
289
|
return this._resolveAndConnect(opts, _resolved => {
|
|
290
|
+
if (this._destroyed || this._closing) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
290
293
|
try {
|
|
291
294
|
this._socket.connect(this.port, this.host, () => {
|
|
292
295
|
// a `secure` connection over a caller-provided socket must still
|
|
@@ -1077,6 +1080,9 @@ class SMTPConnection extends node_events_1.EventEmitter {
|
|
|
1077
1080
|
* @internal
|
|
1078
1081
|
*/
|
|
1079
1082
|
_upgradeConnection(callback) {
|
|
1083
|
+
if (this._destroyed || this._closing) {
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1080
1086
|
// RFC 3207 section 6: the client MUST discard any knowledge obtained from
|
|
1081
1087
|
// the server that was not received over the TLS-protected session. Drop any
|
|
1082
1088
|
// buffered input received before the handshake so a man-in-the-middle cannot
|
|
@@ -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,26 +135,74 @@ 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
|
}
|
|
154
168
|
setImmediate(() => this._processMessages());
|
|
155
169
|
return true;
|
|
156
170
|
}
|
|
171
|
+
/**
|
|
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
|
+
}
|
|
157
206
|
/**
|
|
158
207
|
* Closes the pool. Idle connections are closed at once and a connection in the middle of a
|
|
159
208
|
* delivery finishes it first, unless `force` is set: then it is closed too and its message
|
|
@@ -254,6 +303,7 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
254
303
|
this.emit('idle');
|
|
255
304
|
}
|
|
256
305
|
const entry = (connection.queueEntry = this._queue.shift());
|
|
306
|
+
entry.resource = connection;
|
|
257
307
|
entry.messageId = (connection.queueEntry.mail.message.getHeader('message-id') || '').replace(/[<>\s]/g, '');
|
|
258
308
|
connection.available = false;
|
|
259
309
|
this.logger.debug({
|
|
@@ -425,6 +475,7 @@ class SMTPPool extends node_events_1.EventEmitter {
|
|
|
425
475
|
messageId: connection.queueEntry.messageId,
|
|
426
476
|
action: 'requeue'
|
|
427
477
|
}, 'Re-queued message <%s> for #%s. Attempt: #%s', connection.queueEntry.messageId, connection.id, connection.queueEntry.requeueAttempts);
|
|
478
|
+
connection.queueEntry.resource = undefined;
|
|
428
479
|
this._queue.unshift(connection.queueEntry);
|
|
429
480
|
connection.queueEntry = false;
|
|
430
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": [
|