mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2026-11-21 21:06:12 +07:00
node_modules: update (#362)
Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
This commit is contained in:
1 parent
4a48500d96
commit
aefdaa6a6c
49 files changed
+1316
-295
No files matched your search
+47
-35
@@ -21,6 +21,7 @@ const MESSAGE_AUTH_KEYS = ['type', 'user', 'pass', 'accessToken', 'refreshToken'
|
||||
class SMTPTransport extends EventEmitter {
|
||||
constructor(options) {
|
||||
super();
|
||||
this.supportsAbortSignal = true;
|
||||
options = options || {};
|
||||
if (typeof options === 'string') {
|
||||
options = {
|
||||
@@ -115,13 +116,46 @@ class SMTPTransport extends EventEmitter {
|
||||
* @param callback Callback function
|
||||
*/
|
||||
send(mail, callback) {
|
||||
const signal = mail.data.signal;
|
||||
let returned = false;
|
||||
let connection;
|
||||
let perCallAuth;
|
||||
const cleanupPerCallAuth = () => {
|
||||
if (perCallAuth && perCallAuth !== this.auth && perCallAuth.oauth2) {
|
||||
perCallAuth.oauth2.removeAllListeners();
|
||||
}
|
||||
perCallAuth = null;
|
||||
};
|
||||
const finish = (err, info) => {
|
||||
if (returned) {
|
||||
return;
|
||||
}
|
||||
returned = true;
|
||||
signal?.removeEventListener('abort', onAbort);
|
||||
cleanupPerCallAuth();
|
||||
connection?.close();
|
||||
callback(err, info);
|
||||
};
|
||||
function onAbort() {
|
||||
finish(errors.createAbortError(signal));
|
||||
}
|
||||
if (signal) {
|
||||
signal.addEventListener('abort', onAbort, { once: true });
|
||||
if (signal.aborted) {
|
||||
setImmediate(onAbort);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// the proxy handshake, if any, counts against connectionTimeout as well
|
||||
const connectStartedAt = Date.now();
|
||||
this.getSocket(Object.assign({}, this.options, { connectStartedAt }), (err, socketOptions) => {
|
||||
if (returned) {
|
||||
socketOptions && socketOptions.connection?.destroy();
|
||||
return;
|
||||
}
|
||||
if (err) {
|
||||
return callback(err);
|
||||
return finish(err);
|
||||
}
|
||||
let returned = false;
|
||||
let options = this.options;
|
||||
if (socketOptions && socketOptions.connection) {
|
||||
this.logger.info({
|
||||
@@ -135,24 +169,9 @@ class SMTPTransport extends EventEmitter {
|
||||
// only copy options if we need to modify it
|
||||
options = Object.assign(shared.assign(false, options), socketOptions);
|
||||
}
|
||||
const connection = new SMTPConnection(options);
|
||||
connection._connectStartedAt = connectStartedAt;
|
||||
let perCallAuth;
|
||||
const cleanupPerCallAuth = () => {
|
||||
if (perCallAuth && perCallAuth !== this.auth && perCallAuth.oauth2) {
|
||||
perCallAuth.oauth2.removeAllListeners();
|
||||
}
|
||||
perCallAuth = null;
|
||||
};
|
||||
connection.once('error', err => {
|
||||
if (returned) {
|
||||
return;
|
||||
}
|
||||
returned = true;
|
||||
cleanupPerCallAuth();
|
||||
connection.close();
|
||||
return callback(err);
|
||||
});
|
||||
const smtp = (connection = new SMTPConnection(options));
|
||||
smtp._connectStartedAt = connectStartedAt;
|
||||
smtp.once('error', err => finish(err));
|
||||
const sendMessage = () => {
|
||||
const envelope = mail.message.getEnvelope();
|
||||
const messageId = mail.message.messageId();
|
||||
@@ -171,20 +190,17 @@ class SMTPTransport extends EventEmitter {
|
||||
tnx: 'send',
|
||||
messageId
|
||||
}, 'Sending message %s to <%s>', messageId, recipients.join(', '));
|
||||
connection.send(envelope, mail.message.createReadStream(), (err, info) => {
|
||||
smtp.send(envelope, mail.message.createReadStream(), (err, info) => {
|
||||
if (returned) {
|
||||
// the connection error handler has already reported this send
|
||||
return;
|
||||
}
|
||||
returned = true;
|
||||
cleanupPerCallAuth();
|
||||
connection.close();
|
||||
if (err) {
|
||||
this.logger.error({
|
||||
err,
|
||||
tnx: 'send'
|
||||
}, 'Send error for %s: %s', messageId, err.message);
|
||||
return callback(err);
|
||||
return finish(err);
|
||||
}
|
||||
info.envelope = {
|
||||
from: envelope.from,
|
||||
@@ -192,7 +208,7 @@ class SMTPTransport extends EventEmitter {
|
||||
};
|
||||
info.messageId = messageId;
|
||||
try {
|
||||
return callback(null, info);
|
||||
return finish(null, info);
|
||||
}
|
||||
catch (E) {
|
||||
this.logger.error({
|
||||
@@ -202,27 +218,23 @@ class SMTPTransport extends EventEmitter {
|
||||
}
|
||||
});
|
||||
};
|
||||
connection.connect(err => {
|
||||
smtp.connect(err => {
|
||||
if (returned) {
|
||||
return;
|
||||
}
|
||||
if (err) {
|
||||
// the server closed the connection before the greeting
|
||||
returned = true;
|
||||
connection.close();
|
||||
return callback(err);
|
||||
return finish(err);
|
||||
}
|
||||
perCallAuth = this.getAuth(mail.data.auth);
|
||||
if (perCallAuth && (connection.allowsAuth || options.forceAuth)) {
|
||||
connection.login(perCallAuth, err => {
|
||||
if (perCallAuth && (smtp.allowsAuth || options.forceAuth)) {
|
||||
smtp.login(perCallAuth, err => {
|
||||
cleanupPerCallAuth();
|
||||
if (returned) {
|
||||
return;
|
||||
}
|
||||
if (err) {
|
||||
returned = true;
|
||||
connection.close();
|
||||
return callback(err);
|
||||
return finish(err);
|
||||
}
|
||||
sendMessage();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user