mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2026-10-09 09:59:45 +07:00
node_modules: update (#338)
Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
This commit is contained in:
1 parent
e1936242ed
commit
a9c5eb6c35
39 files changed
+799
-388
No files matched your search
+2
-1
@@ -17,7 +17,7 @@ export interface SMTPPoolOptions extends SMTPTransportOptions {
|
||||
rateLimit?: number | undefined;
|
||||
/** Time window for rateLimit in milliseconds, defaults to 1000 */
|
||||
rateDelta?: number | undefined;
|
||||
/** How many times a message is requeued when its connection closes while sending, unlimited when not set or negative */
|
||||
/** How many times a message is requeued when its connection closes while sending, defaults to 5, a negative value means unlimited */
|
||||
maxRequeues?: number | undefined;
|
||||
}
|
||||
/**
|
||||
@@ -26,6 +26,7 @@ export interface SMTPPoolOptions extends SMTPTransportOptions {
|
||||
export type SMTPPoolResolvedOptions = SMTPPoolOptions & {
|
||||
maxConnections: number;
|
||||
maxMessages: number;
|
||||
maxRequeues: number;
|
||||
};
|
||||
/**
|
||||
* Result of a message sent through the pool, same as for the SMTP transport
|
||||
|
||||
+31
-5
@@ -43,6 +43,10 @@ const index_js_2 = __importDefault(require("../well-known/index.js"));
|
||||
const shared = __importStar(require("../shared/index.js"));
|
||||
const errors = __importStar(require("../errors.js"));
|
||||
const packageData = __importStar(require("../package-info.js"));
|
||||
/** First delay before a requeued message is retried, doubled on every further requeue */
|
||||
const REQUEUE_BASE_DELAY = 50;
|
||||
/** Upper bound for the requeue delay */
|
||||
const REQUEUE_MAX_DELAY = 2000;
|
||||
/**
|
||||
* Creates a SMTP pool transport object for Nodemailer
|
||||
*
|
||||
@@ -74,6 +78,8 @@ class SMTPPool extends node_events_1.EventEmitter {
|
||||
);
|
||||
this.options.maxConnections = this.options.maxConnections || 5;
|
||||
this.options.maxMessages = this.options.maxMessages || 100;
|
||||
// a default bound, a server that closes every connection before the greeting would otherwise be retried forever
|
||||
this.options.maxRequeues = typeof this.options.maxRequeues === 'number' ? this.options.maxRequeues : 5;
|
||||
this.logger = shared.getLogger(this.options, {
|
||||
component: this.options.component || 'smtp-pool'
|
||||
});
|
||||
@@ -117,6 +123,10 @@ class SMTPPool extends node_events_1.EventEmitter {
|
||||
*/
|
||||
send(mail, callback) {
|
||||
if (this._closed) {
|
||||
// Mail.sendMail ignores the return value, so without a callback its promise would never settle
|
||||
const err = new Error('Connection pool was closed');
|
||||
err.code = errors.ECONNECTION;
|
||||
setImmediate(() => callback(err));
|
||||
return false;
|
||||
}
|
||||
this._queue.push({
|
||||
@@ -330,15 +340,22 @@ class SMTPPool extends node_events_1.EventEmitter {
|
||||
// Note that we must wait a bit.. because the callback of the 'error' handler might be called
|
||||
// in the next event loop
|
||||
setTimeout(() => {
|
||||
let delay = 0;
|
||||
if (connection.queueEntry) {
|
||||
if (this._shouldRequeuOnConnectionClose(connection.queueEntry)) {
|
||||
this._requeueEntryOnConnectionClose(connection);
|
||||
delay = this._requeueEntryOnConnectionClose(connection);
|
||||
}
|
||||
else {
|
||||
this._failDeliveryOnConnectionClose(connection);
|
||||
}
|
||||
}
|
||||
this._continueProcessing();
|
||||
if (delay) {
|
||||
// back off, a server that keeps dropping connections is not hammered
|
||||
setTimeout(() => this._continueProcessing(), delay);
|
||||
}
|
||||
else {
|
||||
this._continueProcessing();
|
||||
}
|
||||
}, 50);
|
||||
}
|
||||
else {
|
||||
@@ -353,7 +370,7 @@ class SMTPPool extends node_events_1.EventEmitter {
|
||||
}
|
||||
/** @internal */
|
||||
_shouldRequeuOnConnectionClose(queueEntry) {
|
||||
if (this.options.maxRequeues === undefined || this.options.maxRequeues < 0) {
|
||||
if (this.options.maxRequeues < 0) {
|
||||
return true;
|
||||
}
|
||||
return queueEntry.requeueAttempts < this.options.maxRequeues;
|
||||
@@ -362,7 +379,9 @@ class SMTPPool extends node_events_1.EventEmitter {
|
||||
_failDeliveryOnConnectionClose(connection) {
|
||||
if (connection.queueEntry && connection.queueEntry.callback) {
|
||||
try {
|
||||
connection.queueEntry.callback(new Error('Reached maximum number of retries after connection was closed'));
|
||||
const err = new Error('Reached maximum number of retries after connection was closed');
|
||||
err.code = errors.ECONNECTION;
|
||||
connection.queueEntry.callback(err);
|
||||
}
|
||||
catch (E) {
|
||||
this.logger.error({
|
||||
@@ -377,6 +396,7 @@ class SMTPPool extends node_events_1.EventEmitter {
|
||||
}
|
||||
/** @internal */
|
||||
_requeueEntryOnConnectionClose(connection) {
|
||||
const delay = Math.min(REQUEUE_BASE_DELAY * 2 ** connection.queueEntry.requeueAttempts, REQUEUE_MAX_DELAY);
|
||||
connection.queueEntry.requeueAttempts += 1;
|
||||
this.logger.debug({
|
||||
tnx: 'pool',
|
||||
@@ -386,6 +406,7 @@ class SMTPPool extends node_events_1.EventEmitter {
|
||||
}, 'Re-queued message <%s> for #%s. Attempt: #%s', connection.queueEntry.messageId, connection.id, connection.queueEntry.requeueAttempts);
|
||||
this._queue.unshift(connection.queueEntry);
|
||||
connection.queueEntry = false;
|
||||
return delay;
|
||||
}
|
||||
/**
|
||||
* Continue to process message if the pool hasn't closed
|
||||
@@ -506,10 +527,15 @@ class SMTPPool extends node_events_1.EventEmitter {
|
||||
connection.quit();
|
||||
return done(null, true);
|
||||
};
|
||||
connection.connect(() => {
|
||||
connection.connect(err => {
|
||||
if (returned) {
|
||||
return;
|
||||
}
|
||||
if (err) {
|
||||
returned = true;
|
||||
connection.close();
|
||||
return done(err);
|
||||
}
|
||||
if (auth && (connection.allowsAuth || options.forceAuth)) {
|
||||
connection.login(auth, err => {
|
||||
if (returned) {
|
||||
|
||||
+27
-29
@@ -66,7 +66,7 @@ class PoolResource extends node_events_1.EventEmitter {
|
||||
method: 'XOAUTH2'
|
||||
};
|
||||
oauth2.on('token', (token) => this.pool.mailer.emit('token', token));
|
||||
oauth2.on('error', err => this.emit('error', err));
|
||||
oauth2.on('error', err => this._fail(err));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -89,6 +89,19 @@ class PoolResource extends node_events_1.EventEmitter {
|
||||
this._connected = false;
|
||||
this.messages = 0;
|
||||
this.available = true;
|
||||
this._failed = false;
|
||||
}
|
||||
/**
|
||||
* Emits 'error' for the first failure only. A dead resource can report the same failure more
|
||||
* than once (the connection error, then the send callback), the pool handles it once
|
||||
* @internal
|
||||
*/
|
||||
_fail(err) {
|
||||
if (this._failed) {
|
||||
return;
|
||||
}
|
||||
this._failed = true;
|
||||
this.emit('error', err);
|
||||
}
|
||||
/**
|
||||
* Initiates a connection to the SMTP server
|
||||
@@ -101,7 +114,7 @@ class PoolResource extends node_events_1.EventEmitter {
|
||||
// nothing was connected, so no 'close' event is coming that would free the
|
||||
// slot this resource holds in the pool, report the failure the way a failed
|
||||
// login does
|
||||
this.emit('error', err);
|
||||
this._fail(err);
|
||||
return callback(err);
|
||||
}
|
||||
let returned = false;
|
||||
@@ -118,8 +131,8 @@ class PoolResource extends node_events_1.EventEmitter {
|
||||
options = Object.assign((0, index_js_2.assign)(false, options), socketOptions);
|
||||
}
|
||||
this.connection = new index_js_1.default(options);
|
||||
this.connection.once('error', err => {
|
||||
this.emit('error', err);
|
||||
this.connection.on('error', err => {
|
||||
this._fail(err);
|
||||
if (returned) {
|
||||
return;
|
||||
}
|
||||
@@ -128,31 +141,16 @@ class PoolResource extends node_events_1.EventEmitter {
|
||||
});
|
||||
this.connection.once('end', () => {
|
||||
this.close();
|
||||
returned = true;
|
||||
});
|
||||
this.connection.connect(err => {
|
||||
if (returned) {
|
||||
return;
|
||||
}
|
||||
returned = true;
|
||||
const timer = setTimeout(() => {
|
||||
if (returned) {
|
||||
return;
|
||||
}
|
||||
// still have not returned, this means we have an unexpected connection close
|
||||
const err = new Error('Unexpected socket close');
|
||||
if (this.connection && this.connection.upgrading) {
|
||||
// starttls connection errors
|
||||
err.code = errors.ETLS;
|
||||
}
|
||||
callback(err);
|
||||
}, 1000);
|
||||
try {
|
||||
timer.unref();
|
||||
}
|
||||
catch (_E) {
|
||||
// Ignore. Happens on envs with non-node timer implementation
|
||||
}
|
||||
});
|
||||
this.connection.connect(() => {
|
||||
if (returned) {
|
||||
if (err) {
|
||||
// a close before the greeting, the 'end' that follows closes this resource
|
||||
// and the pool requeues or fails the entry, bounded by maxRequeues
|
||||
returned = true;
|
||||
return;
|
||||
}
|
||||
if (this.auth && (this.connection.allowsAuth || options.forceAuth)) {
|
||||
@@ -163,7 +161,7 @@ class PoolResource extends node_events_1.EventEmitter {
|
||||
returned = true;
|
||||
if (err) {
|
||||
this.connection.close();
|
||||
this.emit('error', err);
|
||||
this._fail(err);
|
||||
return callback(err);
|
||||
}
|
||||
this._connected = true;
|
||||
@@ -215,7 +213,7 @@ class PoolResource extends node_events_1.EventEmitter {
|
||||
this.messages++;
|
||||
if (err) {
|
||||
this.connection.close();
|
||||
this.emit('error', err);
|
||||
this._fail(err);
|
||||
return callback(err);
|
||||
}
|
||||
info.envelope = {
|
||||
@@ -228,7 +226,7 @@ class PoolResource extends node_events_1.EventEmitter {
|
||||
const err = new Error('Resource exhausted');
|
||||
err.code = errors.EMAXLIMIT;
|
||||
this.connection.close();
|
||||
this.emit('error', err);
|
||||
this._fail(err);
|
||||
}
|
||||
else {
|
||||
this.pool._checkRateLimit(() => {
|
||||
|
||||
Reference in new issue
Block a user