mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2026-05-06 17:30:35 +07:00
node_modules: update (#290)
Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
This commit is contained in:
236
node_modules/nodemailer/lib/shared/index.js
generated
vendored
236
node_modules/nodemailer/lib/shared/index.js
generated
vendored
@@ -30,34 +30,28 @@ try {
|
||||
module.exports.networkInterfaces = networkInterfaces;
|
||||
|
||||
const isFamilySupported = (family, allowInternal) => {
|
||||
let networkInterfaces = module.exports.networkInterfaces;
|
||||
if (!networkInterfaces) {
|
||||
const ifaces = module.exports.networkInterfaces;
|
||||
if (!ifaces) {
|
||||
// hope for the best
|
||||
return true;
|
||||
}
|
||||
|
||||
const familySupported =
|
||||
// crux that replaces Object.values(networkInterfaces) as Object.values is not supported in nodejs v6
|
||||
Object.keys(networkInterfaces)
|
||||
.map(key => networkInterfaces[key])
|
||||
// crux that replaces .flat() as it is not supported in older Node versions (v10 and older)
|
||||
.reduce((acc, val) => acc.concat(val), [])
|
||||
.filter(i => !i.internal || allowInternal)
|
||||
.filter(i => i.family === 'IPv' + family || i.family === family).length > 0;
|
||||
|
||||
return familySupported;
|
||||
return Object.keys(ifaces)
|
||||
.map(key => ifaces[key])
|
||||
.reduce((acc, val) => acc.concat(val), [])
|
||||
.filter(i => !i.internal || allowInternal)
|
||||
.some(i => i.family === 'IPv' + family || i.family === family);
|
||||
};
|
||||
|
||||
const resolver = (family, hostname, options, callback) => {
|
||||
const resolve = (family, hostname, options, callback) => {
|
||||
options = options || {};
|
||||
const familySupported = isFamilySupported(family, options.allowInternalNetworkInterfaces);
|
||||
|
||||
if (!familySupported) {
|
||||
if (!isFamilySupported(family, options.allowInternalNetworkInterfaces)) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
const resolver = dns.Resolver ? new dns.Resolver(options) : dns;
|
||||
resolver['resolve' + family](hostname, (err, addresses) => {
|
||||
const dnsResolver = dns.Resolver ? new dns.Resolver(options) : dns;
|
||||
dnsResolver['resolve' + family](hostname, (err, addresses) => {
|
||||
if (err) {
|
||||
switch (err.code) {
|
||||
case dns.NODATA:
|
||||
@@ -82,15 +76,10 @@ const formatDNSValue = (value, extra) => {
|
||||
return Object.assign({}, extra || {});
|
||||
}
|
||||
|
||||
let addresses = value.addresses || [];
|
||||
const addresses = value.addresses || [];
|
||||
|
||||
// Select a random address from available addresses, or null if none
|
||||
let host = null;
|
||||
if (addresses.length === 1) {
|
||||
host = addresses[0];
|
||||
} else if (addresses.length > 1) {
|
||||
host = addresses[Math.floor(Math.random() * addresses.length)];
|
||||
}
|
||||
const host = addresses.length > 0 ? addresses[Math.floor(Math.random() * addresses.length)] : null;
|
||||
|
||||
return Object.assign(
|
||||
{
|
||||
@@ -112,7 +101,7 @@ module.exports.resolveHostname = (options, callback) => {
|
||||
|
||||
if (!options.host || net.isIP(options.host)) {
|
||||
// nothing to do here
|
||||
let value = {
|
||||
const value = {
|
||||
addresses: [options.host],
|
||||
servername: options.servername || false
|
||||
};
|
||||
@@ -164,14 +153,14 @@ module.exports.resolveHostname = (options, callback) => {
|
||||
let ipv4Error = null;
|
||||
let ipv6Error = null;
|
||||
|
||||
resolver(4, options.host, options, (err, addresses) => {
|
||||
resolve(4, options.host, options, (err, addresses) => {
|
||||
if (err) {
|
||||
ipv4Error = err;
|
||||
} else {
|
||||
ipv4Addresses = addresses || [];
|
||||
}
|
||||
|
||||
resolver(6, options.host, options, (err, addresses) => {
|
||||
resolve(6, options.host, options, (err, addresses) => {
|
||||
if (err) {
|
||||
ipv6Error = err;
|
||||
} else {
|
||||
@@ -179,10 +168,10 @@ module.exports.resolveHostname = (options, callback) => {
|
||||
}
|
||||
|
||||
// Combine addresses: IPv4 first, then IPv6
|
||||
let allAddresses = ipv4Addresses.concat(ipv6Addresses);
|
||||
const allAddresses = ipv4Addresses.concat(ipv6Addresses);
|
||||
|
||||
if (allAddresses.length) {
|
||||
let value = {
|
||||
const value = {
|
||||
addresses: allAddresses,
|
||||
servername: options.servername || options.host
|
||||
};
|
||||
@@ -240,7 +229,7 @@ module.exports.resolveHostname = (options, callback) => {
|
||||
}
|
||||
|
||||
// Get all supported addresses from dns.lookup
|
||||
let supportedAddresses = addresses
|
||||
const supportedAddresses = addresses
|
||||
? addresses.filter(addr => isFamilySupported(addr.family)).map(addr => addr.address)
|
||||
: [];
|
||||
|
||||
@@ -259,7 +248,7 @@ module.exports.resolveHostname = (options, callback) => {
|
||||
);
|
||||
}
|
||||
|
||||
let value = {
|
||||
const value = {
|
||||
addresses: supportedAddresses.length ? supportedAddresses : [options.host],
|
||||
servername: options.servername || options.host
|
||||
};
|
||||
@@ -304,95 +293,78 @@ module.exports.resolveHostname = (options, callback) => {
|
||||
*/
|
||||
module.exports.parseConnectionUrl = str => {
|
||||
str = str || '';
|
||||
let options = {};
|
||||
const options = {};
|
||||
const url = urllib.parse(str, true);
|
||||
|
||||
[urllib.parse(str, true)].forEach(url => {
|
||||
let auth;
|
||||
switch (url.protocol) {
|
||||
case 'smtp:':
|
||||
options.secure = false;
|
||||
break;
|
||||
case 'smtps:':
|
||||
options.secure = true;
|
||||
break;
|
||||
case 'direct:':
|
||||
options.direct = true;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (url.protocol) {
|
||||
case 'smtp:':
|
||||
options.secure = false;
|
||||
if (!isNaN(url.port) && Number(url.port)) {
|
||||
options.port = Number(url.port);
|
||||
}
|
||||
|
||||
if (url.hostname) {
|
||||
options.host = url.hostname;
|
||||
}
|
||||
|
||||
if (url.auth) {
|
||||
const auth = url.auth.split(':');
|
||||
options.auth = {
|
||||
user: auth.shift(),
|
||||
pass: auth.join(':')
|
||||
};
|
||||
}
|
||||
|
||||
Object.keys(url.query || {}).forEach(key => {
|
||||
let obj = options;
|
||||
let lKey = key;
|
||||
let value = url.query[key];
|
||||
|
||||
if (!isNaN(value)) {
|
||||
value = Number(value);
|
||||
}
|
||||
|
||||
switch (value) {
|
||||
case 'true':
|
||||
value = true;
|
||||
break;
|
||||
case 'smtps:':
|
||||
options.secure = true;
|
||||
break;
|
||||
case 'direct:':
|
||||
options.direct = true;
|
||||
case 'false':
|
||||
value = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isNaN(url.port) && Number(url.port)) {
|
||||
options.port = Number(url.port);
|
||||
// tls is nested object
|
||||
if (key.indexOf('tls.') === 0) {
|
||||
lKey = key.substr(4);
|
||||
if (!options.tls) {
|
||||
options.tls = {};
|
||||
}
|
||||
obj = options.tls;
|
||||
} else if (key.indexOf('.') >= 0) {
|
||||
// ignore nested properties besides tls
|
||||
return;
|
||||
}
|
||||
|
||||
if (url.hostname) {
|
||||
options.host = url.hostname;
|
||||
if (!(lKey in obj)) {
|
||||
obj[lKey] = value;
|
||||
}
|
||||
|
||||
if (url.auth) {
|
||||
auth = url.auth.split(':');
|
||||
|
||||
if (!options.auth) {
|
||||
options.auth = {};
|
||||
}
|
||||
|
||||
options.auth.user = auth.shift();
|
||||
options.auth.pass = auth.join(':');
|
||||
}
|
||||
|
||||
Object.keys(url.query || {}).forEach(key => {
|
||||
let obj = options;
|
||||
let lKey = key;
|
||||
let value = url.query[key];
|
||||
|
||||
if (!isNaN(value)) {
|
||||
value = Number(value);
|
||||
}
|
||||
|
||||
switch (value) {
|
||||
case 'true':
|
||||
value = true;
|
||||
break;
|
||||
case 'false':
|
||||
value = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// tls is nested object
|
||||
if (key.indexOf('tls.') === 0) {
|
||||
lKey = key.substr(4);
|
||||
if (!options.tls) {
|
||||
options.tls = {};
|
||||
}
|
||||
obj = options.tls;
|
||||
} else if (key.indexOf('.') >= 0) {
|
||||
// ignore nested properties besides tls
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(lKey in obj)) {
|
||||
obj[lKey] = value;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return options;
|
||||
};
|
||||
|
||||
module.exports._logFunc = (logger, level, defaults, data, message, ...args) => {
|
||||
let entry = {};
|
||||
|
||||
Object.keys(defaults || {}).forEach(key => {
|
||||
if (key !== 'level') {
|
||||
entry[key] = defaults[key];
|
||||
}
|
||||
});
|
||||
|
||||
Object.keys(data || {}).forEach(key => {
|
||||
if (key !== 'level') {
|
||||
entry[key] = data[key];
|
||||
}
|
||||
});
|
||||
const entry = Object.assign({}, defaults || {}, data || {});
|
||||
delete entry.level;
|
||||
|
||||
logger[level](entry, message, ...args);
|
||||
};
|
||||
@@ -407,8 +379,8 @@ module.exports._logFunc = (logger, level, defaults, data, message, ...args) => {
|
||||
module.exports.getLogger = (options, defaults) => {
|
||||
options = options || {};
|
||||
|
||||
let response = {};
|
||||
let levels = ['trace', 'debug', 'info', 'warn', 'error', 'fatal'];
|
||||
const response = {};
|
||||
const levels = ['trace', 'debug', 'info', 'warn', 'error', 'fatal'];
|
||||
|
||||
if (!options.logger) {
|
||||
// use vanity logger
|
||||
@@ -418,12 +390,7 @@ module.exports.getLogger = (options, defaults) => {
|
||||
return response;
|
||||
}
|
||||
|
||||
let logger = options.logger;
|
||||
|
||||
if (options.logger === true) {
|
||||
// create console logger
|
||||
logger = createDefaultLogger(levels);
|
||||
}
|
||||
const logger = options.logger === true ? createDefaultLogger(levels) : options.logger;
|
||||
|
||||
levels.forEach(level => {
|
||||
response[level] = (data, message, ...args) => {
|
||||
@@ -443,8 +410,8 @@ module.exports.getLogger = (options, defaults) => {
|
||||
*/
|
||||
module.exports.callbackPromise = (resolve, reject) =>
|
||||
function () {
|
||||
let args = Array.from(arguments);
|
||||
let err = args.shift();
|
||||
const args = Array.from(arguments);
|
||||
const err = args.shift();
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
@@ -546,8 +513,7 @@ module.exports.resolveContent = (data, key, callback) => {
|
||||
}
|
||||
|
||||
let content = (data && data[key] && data[key].content) || data[key];
|
||||
let contentStream;
|
||||
let encoding = ((typeof data[key] === 'object' && data[key].encoding) || 'utf8')
|
||||
const encoding = ((typeof data[key] === 'object' && data[key].encoding) || 'utf8')
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.replace(/[-_\s]/g, '');
|
||||
@@ -572,10 +538,9 @@ module.exports.resolveContent = (data, key, callback) => {
|
||||
callback(null, value);
|
||||
});
|
||||
} else if (/^https?:\/\//i.test(content.path || content.href)) {
|
||||
contentStream = nmfetch(content.path || content.href);
|
||||
return resolveStream(contentStream, callback);
|
||||
return resolveStream(nmfetch(content.path || content.href), callback);
|
||||
} else if (/^data:/i.test(content.path || content.href)) {
|
||||
let parsedDataUri = module.exports.parseDataURI(content.path || content.href);
|
||||
const parsedDataUri = module.exports.parseDataURI(content.path || content.href);
|
||||
|
||||
if (!parsedDataUri || !parsedDataUri.data) {
|
||||
return callback(null, Buffer.from(0));
|
||||
@@ -600,21 +565,15 @@ module.exports.resolveContent = (data, key, callback) => {
|
||||
* Copies properties from source objects to target objects
|
||||
*/
|
||||
module.exports.assign = function (/* target, ... sources */) {
|
||||
let args = Array.from(arguments);
|
||||
let target = args.shift() || {};
|
||||
const args = Array.from(arguments);
|
||||
const target = args.shift() || {};
|
||||
|
||||
args.forEach(source => {
|
||||
Object.keys(source || {}).forEach(key => {
|
||||
if (['tls', 'auth'].includes(key) && source[key] && typeof source[key] === 'object') {
|
||||
// tls and auth are special keys that need to be enumerated separately
|
||||
// other objects are passed as is
|
||||
if (!target[key]) {
|
||||
// ensure that target has this key
|
||||
target[key] = {};
|
||||
}
|
||||
Object.keys(source[key]).forEach(subKey => {
|
||||
target[key][subKey] = source[key][subKey];
|
||||
});
|
||||
target[key] = Object.assign(target[key] || {}, source[key]);
|
||||
} else {
|
||||
target[key] = source[key];
|
||||
}
|
||||
@@ -631,10 +590,10 @@ module.exports.encodeXText = str => {
|
||||
if (!/[^\x21-\x2A\x2C-\x3C\x3E-\x7E]/.test(str)) {
|
||||
return str;
|
||||
}
|
||||
let buf = Buffer.from(str);
|
||||
const buf = Buffer.from(str);
|
||||
let result = '';
|
||||
for (let i = 0, len = buf.length; i < len; i++) {
|
||||
let c = buf[i];
|
||||
const c = buf[i];
|
||||
if (c < 0x21 || c > 0x7e || c === 0x2b || c === 0x3d) {
|
||||
result += '+' + (c < 0x10 ? '0' : '') + c.toString(16).toUpperCase();
|
||||
} else {
|
||||
@@ -652,7 +611,7 @@ module.exports.encodeXText = str => {
|
||||
*/
|
||||
function resolveStream(stream, callback) {
|
||||
let responded = false;
|
||||
let chunks = [];
|
||||
const chunks = [];
|
||||
let chunklen = 0;
|
||||
|
||||
stream.on('error', err => {
|
||||
@@ -695,13 +654,8 @@ function resolveStream(stream, callback) {
|
||||
* @returns {Object} Bunyan logger instance
|
||||
*/
|
||||
function createDefaultLogger(levels) {
|
||||
let levelMaxLen = 0;
|
||||
let levelNames = new Map();
|
||||
levels.forEach(level => {
|
||||
if (level.length > levelMaxLen) {
|
||||
levelMaxLen = level.length;
|
||||
}
|
||||
});
|
||||
const levelMaxLen = levels.reduce((max, level) => Math.max(max, level.length), 0);
|
||||
const levelNames = new Map();
|
||||
|
||||
levels.forEach(level => {
|
||||
let levelName = level.toUpperCase();
|
||||
@@ -711,7 +665,7 @@ function createDefaultLogger(levels) {
|
||||
levelNames.set(level, levelName);
|
||||
});
|
||||
|
||||
let print = (level, entry, message, ...args) => {
|
||||
const print = (level, entry, message, ...args) => {
|
||||
let prefix = '';
|
||||
if (entry) {
|
||||
if (entry.tnx === 'server') {
|
||||
@@ -735,7 +689,7 @@ function createDefaultLogger(levels) {
|
||||
});
|
||||
};
|
||||
|
||||
let logger = {};
|
||||
const logger = {};
|
||||
levels.forEach(level => {
|
||||
logger[level] = print.bind(null, level);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user