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
+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) {
|
||||
|
||||
Reference in new issue
Block a user