mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2026-11-22 05:25:29 +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
+12
-2
@@ -112,6 +112,11 @@ export interface MailMeta {
|
||||
* declared on Transport, Transporter and Mail
|
||||
*/
|
||||
export interface Transport<T = SentMessageInfo, D extends TransportOptions = TransportOptions> {
|
||||
/**
|
||||
* Set only if send() cancels its own work on mail.data.signal and removes its signal listener
|
||||
* when finished. Without it the signal is still honored up to dispatch, then ignored.
|
||||
*/
|
||||
supportsAbortSignal?: boolean | undefined;
|
||||
/** Transport name, used for logging */
|
||||
name: string;
|
||||
/** Transport version, used for logging */
|
||||
@@ -176,8 +181,13 @@ declare class Mail<out T = SentMessageInfo, out D extends TransportOptions = Tra
|
||||
dkim: DKIM | false;
|
||||
transporter: Transport<T, D>;
|
||||
logger: shared.Logger;
|
||||
/** Closes the transport, the pooled SMTP transport closes its connections */
|
||||
close: () => void;
|
||||
/**
|
||||
* Closes the transport, the pooled SMTP transport closes its connections. With `force` the
|
||||
* pooled transport also closes connections that are delivering a message
|
||||
*/
|
||||
close: (options?: {
|
||||
force?: boolean;
|
||||
}) => void;
|
||||
/** Tells whether the transport can take a message right away */
|
||||
isIdle: () => boolean;
|
||||
/** Checks the configuration, the SMTP transports connect and authenticate for it */
|
||||
|
||||
+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) {
|
||||
|
||||
+10
@@ -13,6 +13,16 @@ import type { SentMessageInfo } from './index.js';
|
||||
* tree is built from, the fields below are the ones the mailer reads on top of those
|
||||
*/
|
||||
export interface SendMailOptions extends MailComposerOptions {
|
||||
/**
|
||||
* Cancel this send, including waiting for plugins or in an SMTP pool queue.
|
||||
* Plugins must cooperate with the signal to stop their own work already in progress.
|
||||
* Supported by SMTP, pooled SMTP and transports declaring supportsAbortSignal. Other
|
||||
* transports ignore the signal once the message is handed to them; a signal that is
|
||||
* already aborted, or aborts during plugin processing, still cancels the send.
|
||||
* Fails with AbortError/EABORT on cancellation, ECONFIG if the value is not an AbortSignal.
|
||||
* Aborting does not prove that the server has not already accepted the message.
|
||||
*/
|
||||
signal?: AbortSignal | undefined;
|
||||
/** DKIM signing options for this message, used instead of the ones of the transporter */
|
||||
dkim?: DKIMOptions | undefined;
|
||||
/** Extra DKIM options for this message, merged over the options of the signer. The SES transport sets skipFields here, the option is not meant for callers */
|
||||
|
||||
Reference in new issue
Block a user