mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2026-06-22 00:46:12 +07:00
node_modules: update (#297)
Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
This commit is contained in:
+15
-6
@@ -6,7 +6,7 @@
|
||||
|
||||
const net = require('net');
|
||||
const tls = require('tls');
|
||||
const urllib = require('url');
|
||||
const urllib = require('../shared/url');
|
||||
const errors = require('../errors');
|
||||
|
||||
/**
|
||||
@@ -19,20 +19,29 @@ const errors = require('../errors');
|
||||
* @param {String} proxyUrl proxy configuration, etg "http://proxy.host:3128/"
|
||||
* @param {Number} destinationPort Port to open in destination host
|
||||
* @param {String} destinationHost Destination hostname
|
||||
* @param {Object} [tlsOptions] Optional TLS options for an HTTPS proxy (e.g. { rejectUnauthorized: false })
|
||||
* @param {Function} callback Callback to run with the rocket object once connection is established
|
||||
*/
|
||||
function httpProxyClient(proxyUrl, destinationPort, destinationHost, callback) {
|
||||
function httpProxyClient(proxyUrl, destinationPort, destinationHost, tlsOptions, callback) {
|
||||
if (typeof tlsOptions === 'function') {
|
||||
callback = tlsOptions;
|
||||
tlsOptions = {};
|
||||
}
|
||||
tlsOptions = tlsOptions || {};
|
||||
|
||||
const proxy = urllib.parse(proxyUrl);
|
||||
|
||||
const options = {
|
||||
const connectOptions = {
|
||||
host: proxy.hostname,
|
||||
port: Number(proxy.port) ? Number(proxy.port) : proxy.protocol === 'https:' ? 443 : 80
|
||||
};
|
||||
|
||||
let connect;
|
||||
if (proxy.protocol === 'https:') {
|
||||
// we can use untrusted proxies as long as we verify actual SMTP certificates
|
||||
options.rejectUnauthorized = false;
|
||||
// Validate the proxy's TLS certificate by default. A caller that uses a
|
||||
// self-signed proxy (e.g. integration tests) opts out explicitly with
|
||||
// tls.rejectUnauthorized === false.
|
||||
connectOptions.rejectUnauthorized = tlsOptions.rejectUnauthorized !== false;
|
||||
connect = tls.connect.bind(tls);
|
||||
} else {
|
||||
connect = net.connect.bind(net);
|
||||
@@ -62,7 +71,7 @@ function httpProxyClient(proxyUrl, destinationPort, destinationHost, callback) {
|
||||
tempSocketErr(err);
|
||||
};
|
||||
|
||||
socket = connect(options, () => {
|
||||
socket = connect(connectOptions, () => {
|
||||
if (finished) {
|
||||
return;
|
||||
}
|
||||
|
||||
+40
-9
@@ -51,9 +51,9 @@ function decodeServerResponse(str) {
|
||||
* * **requireTLS** - forces the client to use STARTTLS
|
||||
* * **name** - the name of the client server
|
||||
* * **localAddress** - outbound address to bind to (see: http://nodejs.org/api/net.html#net_net_connect_options_connectionlistener)
|
||||
* * **greetingTimeout** - Time to wait in ms until greeting message is received from the server (defaults to 10000)
|
||||
* * **connectionTimeout** - how many milliseconds to wait for the connection to establish
|
||||
* * **socketTimeout** - Time of inactivity until the connection is closed (defaults to 1 hour)
|
||||
* * **greetingTimeout** - Time to wait in ms until greeting message is received from the server (defaults to 30 seconds)
|
||||
* * **connectionTimeout** - how many milliseconds to wait for the connection to establish (defaults to 2 minutes)
|
||||
* * **socketTimeout** - Time of inactivity until the connection is closed (defaults to 10 minutes)
|
||||
* * **dnsTimeout** - Time to wait in ms for the DNS requests to be resolved (defaults to 30 seconds)
|
||||
* * **lmtp** - if true, uses LMTP instead of SMTP protocol
|
||||
* * **logger** - bunyan compatible logger interface
|
||||
@@ -211,6 +211,13 @@ class SMTPConnection extends EventEmitter {
|
||||
*/
|
||||
this._closing = false;
|
||||
|
||||
/**
|
||||
* Message DATA stream currently piped to the socket, if any. Tracked so
|
||||
* close() can unpipe it before tearing the socket down.
|
||||
* @private
|
||||
*/
|
||||
this._currentDataStream = false;
|
||||
|
||||
/**
|
||||
* Callbacks for socket's listeners
|
||||
*/
|
||||
@@ -470,6 +477,17 @@ class SMTPConnection extends EventEmitter {
|
||||
|
||||
const socket = (this._socket && this._socket.socket) || this._socket;
|
||||
|
||||
// Detach any in-flight DATA stream from the socket so the source stream
|
||||
// can be garbage-collected once the socket is gone.
|
||||
if (this._currentDataStream) {
|
||||
try {
|
||||
this._currentDataStream.unpipe(this._socket);
|
||||
} catch (_E) {
|
||||
// ignore
|
||||
}
|
||||
this._currentDataStream = false;
|
||||
}
|
||||
|
||||
if (socket && !socket.destroyed) {
|
||||
try {
|
||||
// Clear socket timeout to prevent timer leaks
|
||||
@@ -820,7 +838,7 @@ class SMTPConnection extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
|
||||
let data = (chunk || '').toString('binary');
|
||||
let data = chunk.toString('binary');
|
||||
let lines = (this._remainder + data).split(/\r?\n/);
|
||||
let lastline;
|
||||
|
||||
@@ -953,7 +971,9 @@ class SMTPConnection extends EventEmitter {
|
||||
*/
|
||||
_onEnd() {
|
||||
if (this._socket && !this._socket.destroyed) {
|
||||
this._socket.destroy();
|
||||
// Peer sent FIN — finish our half of the close gracefully rather
|
||||
// than destroying. 'close' fires after the OS finalizes teardown.
|
||||
this._socket.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1005,6 +1025,15 @@ class SMTPConnection extends EventEmitter {
|
||||
opts.servername = this.servername;
|
||||
}
|
||||
|
||||
// Remove all listeners from the plain socket to allow proper garbage
|
||||
// collection. Used on both the TLS-success path and the synchronous
|
||||
// tls.connect() throw path; either way the plain socket is done.
|
||||
const removePlainSocketListeners = () => {
|
||||
socketPlain.removeListener('close', this._onSocketClose);
|
||||
socketPlain.removeListener('end', this._onSocketEnd);
|
||||
socketPlain.removeListener('error', this._onSocketError);
|
||||
};
|
||||
|
||||
this.upgrading = true;
|
||||
// tls.connect is not an asynchronous function however it may still throw errors and requires to be wrapped with try/catch
|
||||
try {
|
||||
@@ -1013,14 +1042,12 @@ class SMTPConnection extends EventEmitter {
|
||||
this.upgrading = false;
|
||||
this._socket.on('data', this._onSocketData);
|
||||
|
||||
// Remove all listeners from the plain socket to allow proper garbage collection
|
||||
socketPlain.removeListener('close', this._onSocketClose);
|
||||
socketPlain.removeListener('end', this._onSocketEnd);
|
||||
socketPlain.removeListener('error', this._onSocketError);
|
||||
removePlainSocketListeners();
|
||||
|
||||
return callback(null, true);
|
||||
});
|
||||
} catch (err) {
|
||||
removePlainSocketListeners();
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -1297,6 +1324,7 @@ class SMTPConnection extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
this._currentDataStream = dataStream;
|
||||
dataStream.pipe(this._socket, {
|
||||
end: false
|
||||
});
|
||||
@@ -1318,6 +1346,9 @@ class SMTPConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
dataStream.once('end', () => {
|
||||
if (this._currentDataStream === dataStream) {
|
||||
this._currentDataStream = false;
|
||||
}
|
||||
this.logger.info(
|
||||
{
|
||||
tnx: 'message',
|
||||
|
||||
Reference in New Issue
Block a user