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
+56
-4
@@ -18,6 +18,16 @@ import crypto from 'node:crypto';
|
||||
* asks a server to accept 100, so a real send is bounded far below this.
|
||||
*/
|
||||
const DEFAULT_MAX_RECIPIENTS = 100000;
|
||||
/**
|
||||
* Duck-typed so that signals from another realm or a polyfill are accepted as well
|
||||
*/
|
||||
function isAbortSignal(value) {
|
||||
return (typeof value === 'object' &&
|
||||
value !== null &&
|
||||
'aborted' in value &&
|
||||
typeof value.addEventListener === 'function' &&
|
||||
typeof value.removeEventListener === 'function');
|
||||
}
|
||||
/**
|
||||
* Creates an object for exposing the Mail API
|
||||
*
|
||||
@@ -119,11 +129,43 @@ class Mail extends EventEmitter {
|
||||
this.getSocket = false;
|
||||
}
|
||||
const mail = new MailMessage(this, data);
|
||||
const signalOption = mail.data.signal;
|
||||
const signal = isAbortSignal(signalOption) ? signalOption : undefined;
|
||||
let settled = false;
|
||||
const removeAbortListener = () => signal?.removeEventListener('abort', onAbort);
|
||||
const finish = (err, info) => {
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
settled = true;
|
||||
removeAbortListener();
|
||||
if (err) {
|
||||
mail.releaseStreams();
|
||||
}
|
||||
done(err, info);
|
||||
};
|
||||
// a failed message is not going to be read anymore, release its content streams
|
||||
const fail = (err) => {
|
||||
mail.releaseStreams();
|
||||
done(err);
|
||||
finish(err);
|
||||
};
|
||||
function onAbort() {
|
||||
fail(errors.createAbortError(signal));
|
||||
}
|
||||
if (signalOption !== undefined && signalOption !== null && !signal) {
|
||||
const err = new Error('The signal option must be an AbortSignal');
|
||||
err.code = errors.ECONFIG;
|
||||
setImmediate(() => fail(err));
|
||||
return promise;
|
||||
}
|
||||
// Mail handles a pre-aborted signal and cancellation during plugin processing for every
|
||||
// transport; a transport without supportsAbortSignal ignores the signal once it is called
|
||||
if (signal) {
|
||||
signal.addEventListener('abort', onAbort, { once: true });
|
||||
if (signal.aborted) {
|
||||
setImmediate(onAbort);
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
this.logger.debug({
|
||||
tnx: 'transport',
|
||||
name: this.transporter.name,
|
||||
@@ -131,6 +173,9 @@ class Mail extends EventEmitter {
|
||||
action: 'send'
|
||||
}, 'Sending mail using %s/%s', this.transporter.name, this.transporter.version);
|
||||
this._processPlugins('compile', mail, err => {
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
if (err) {
|
||||
this.logger.error({
|
||||
err,
|
||||
@@ -168,6 +213,9 @@ class Mail extends EventEmitter {
|
||||
return fail(err);
|
||||
}
|
||||
this._processPlugins('stream', mail, err => {
|
||||
if (settled) {
|
||||
return;
|
||||
}
|
||||
if (err) {
|
||||
this.logger.error({
|
||||
err,
|
||||
@@ -187,16 +235,17 @@ class Mail extends EventEmitter {
|
||||
return dkim.sign(input, mail.data._dkim);
|
||||
});
|
||||
}
|
||||
// The transport takes ownership of cancellation from here, including queued work.
|
||||
removeAbortListener();
|
||||
this.transporter.send(mail, (...args) => {
|
||||
if (args[0]) {
|
||||
mail.releaseStreams();
|
||||
this.logger.error({
|
||||
err: args[0],
|
||||
tnx: 'transport',
|
||||
action: 'send'
|
||||
}, 'Send Error: %s', args[0].message);
|
||||
}
|
||||
done(...args);
|
||||
finish(...args);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -226,6 +275,9 @@ class Mail extends EventEmitter {
|
||||
let pos = 0;
|
||||
let block = 'default';
|
||||
const processPlugins = () => {
|
||||
if (mail.data.signal?.aborted) {
|
||||
return callback(errors.createAbortError(mail.data.signal));
|
||||
}
|
||||
let curplugins = block === 'default' ? defaultPlugins : userPlugins;
|
||||
if (pos >= curplugins.length) {
|
||||
if (block === 'default' && userPlugins.length) {
|
||||
|
||||
Reference in new issue
Block a user