mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2025-08-18 19:44:40 +07:00
node_modules: upgrade
This commit is contained in:
191
node_modules/nodemailer/lib/shared/index.js
generated
vendored
191
node_modules/nodemailer/lib/shared/index.js
generated
vendored
@ -5,14 +5,51 @@
|
||||
const urllib = require('url');
|
||||
const util = require('util');
|
||||
const fs = require('fs');
|
||||
const fetch = require('../fetch');
|
||||
const nmfetch = require('../fetch');
|
||||
const dns = require('dns');
|
||||
const net = require('net');
|
||||
const os = require('os');
|
||||
|
||||
const DNS_TTL = 5 * 60 * 1000;
|
||||
|
||||
const resolver = (family, hostname, callback) => {
|
||||
dns['resolve' + family](hostname, (err, addresses) => {
|
||||
let networkInterfaces;
|
||||
try {
|
||||
networkInterfaces = os.networkInterfaces();
|
||||
} catch (err) {
|
||||
// fails on some systems
|
||||
}
|
||||
|
||||
module.exports.networkInterfaces = networkInterfaces;
|
||||
|
||||
const isFamilySupported = (family, allowInternal) => {
|
||||
let networkInterfaces = module.exports.networkInterfaces;
|
||||
if (!networkInterfaces) {
|
||||
// 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;
|
||||
};
|
||||
|
||||
const resolver = (family, hostname, options, callback) => {
|
||||
options = options || {};
|
||||
const familySupported = isFamilySupported(family, options.allowInternalNetworkInterfaces);
|
||||
|
||||
if (!familySupported) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
const resolver = dns.Resolver ? new dns.Resolver(options) : dns;
|
||||
resolver['resolve' + family](hostname, (err, addresses) => {
|
||||
if (err) {
|
||||
switch (err.code) {
|
||||
case dns.NODATA:
|
||||
@ -20,6 +57,7 @@ const resolver = (family, hostname, callback) => {
|
||||
case dns.NOTIMP:
|
||||
case dns.SERVFAIL:
|
||||
case dns.CONNREFUSED:
|
||||
case dns.REFUSED:
|
||||
case 'EAI_AGAIN':
|
||||
return callback(null, []);
|
||||
}
|
||||
@ -30,100 +68,195 @@ const resolver = (family, hostname, callback) => {
|
||||
};
|
||||
|
||||
const dnsCache = (module.exports.dnsCache = new Map());
|
||||
|
||||
const formatDNSValue = (value, extra) => {
|
||||
if (!value) {
|
||||
return Object.assign({}, extra || {});
|
||||
}
|
||||
|
||||
return Object.assign(
|
||||
{
|
||||
servername: value.servername,
|
||||
host:
|
||||
!value.addresses || !value.addresses.length
|
||||
? null
|
||||
: value.addresses.length === 1
|
||||
? value.addresses[0]
|
||||
: value.addresses[Math.floor(Math.random() * value.addresses.length)]
|
||||
},
|
||||
extra || {}
|
||||
);
|
||||
};
|
||||
|
||||
module.exports.resolveHostname = (options, callback) => {
|
||||
options = options || {};
|
||||
|
||||
if (!options.host && options.servername) {
|
||||
options.host = options.servername;
|
||||
}
|
||||
|
||||
if (!options.host || net.isIP(options.host)) {
|
||||
// nothing to do here
|
||||
let value = {
|
||||
host: options.host,
|
||||
addresses: [options.host],
|
||||
servername: options.servername || false
|
||||
};
|
||||
return callback(null, value);
|
||||
return callback(
|
||||
null,
|
||||
formatDNSValue(value, {
|
||||
cached: false
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
let cached;
|
||||
|
||||
if (dnsCache.has(options.host)) {
|
||||
cached = dnsCache.get(options.host);
|
||||
|
||||
if (!cached.expires || cached.expires >= Date.now()) {
|
||||
return callback(null, {
|
||||
host: cached.value.host,
|
||||
servername: cached.value.servername,
|
||||
_cached: true
|
||||
});
|
||||
return callback(
|
||||
null,
|
||||
formatDNSValue(cached.value, {
|
||||
cached: true
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
resolver(4, options.host, (err, addresses) => {
|
||||
resolver(4, options.host, options, (err, addresses) => {
|
||||
if (err) {
|
||||
if (cached) {
|
||||
// ignore error, use expired value
|
||||
return callback(null, cached.value);
|
||||
return callback(
|
||||
null,
|
||||
formatDNSValue(cached.value, {
|
||||
cached: true,
|
||||
error: err
|
||||
})
|
||||
);
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (addresses && addresses.length) {
|
||||
let value = {
|
||||
host: addresses[0] || options.host,
|
||||
addresses,
|
||||
servername: options.servername || options.host
|
||||
};
|
||||
|
||||
dnsCache.set(options.host, {
|
||||
value,
|
||||
expires: Date.now() + DNS_TTL
|
||||
expires: Date.now() + (options.dnsTtl || DNS_TTL)
|
||||
});
|
||||
return callback(null, value);
|
||||
|
||||
return callback(
|
||||
null,
|
||||
formatDNSValue(value, {
|
||||
cached: false
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
resolver(6, options.host, (err, addresses) => {
|
||||
resolver(6, options.host, options, (err, addresses) => {
|
||||
if (err) {
|
||||
if (cached) {
|
||||
// ignore error, use expired value
|
||||
return callback(null, cached.value);
|
||||
return callback(
|
||||
null,
|
||||
formatDNSValue(cached.value, {
|
||||
cached: true,
|
||||
error: err
|
||||
})
|
||||
);
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (addresses && addresses.length) {
|
||||
let value = {
|
||||
host: addresses[0] || options.host,
|
||||
addresses,
|
||||
servername: options.servername || options.host
|
||||
};
|
||||
|
||||
dnsCache.set(options.host, {
|
||||
value,
|
||||
expires: Date.now() + DNS_TTL
|
||||
expires: Date.now() + (options.dnsTtl || DNS_TTL)
|
||||
});
|
||||
return callback(null, value);
|
||||
|
||||
return callback(
|
||||
null,
|
||||
formatDNSValue(value, {
|
||||
cached: false
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
dns.lookup(options.host, {}, (err, address) => {
|
||||
dns.lookup(options.host, { all: true }, (err, addresses) => {
|
||||
if (err) {
|
||||
if (cached) {
|
||||
// ignore error, use expired value
|
||||
return callback(null, cached.value);
|
||||
return callback(
|
||||
null,
|
||||
formatDNSValue(cached.value, {
|
||||
cached: true,
|
||||
error: err
|
||||
})
|
||||
);
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
let address = addresses
|
||||
? addresses
|
||||
.filter(addr => isFamilySupported(addr.family))
|
||||
.map(addr => addr.address)
|
||||
.shift()
|
||||
: false;
|
||||
|
||||
if (addresses && addresses.length && !address) {
|
||||
// there are addresses but none can be used
|
||||
let err = new Error(`Can not use IPv${addresses[0].family} addresses with current network`);
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!address && cached) {
|
||||
// nothing was found, fallback to cached value
|
||||
return callback(null, cached.value);
|
||||
return callback(
|
||||
null,
|
||||
formatDNSValue(cached.value, {
|
||||
cached: true
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
let value = {
|
||||
host: address || options.host,
|
||||
addresses: address ? [address] : [options.host],
|
||||
servername: options.servername || options.host
|
||||
};
|
||||
|
||||
dnsCache.set(options.host, {
|
||||
value,
|
||||
expires: Date.now() + DNS_TTL
|
||||
expires: Date.now() + (options.dnsTtl || DNS_TTL)
|
||||
});
|
||||
return callback(null, value);
|
||||
|
||||
return callback(
|
||||
null,
|
||||
formatDNSValue(value, {
|
||||
cached: false
|
||||
})
|
||||
);
|
||||
});
|
||||
} catch (err) {
|
||||
if (cached) {
|
||||
// ignore error, use expired value
|
||||
return callback(null, cached.value);
|
||||
return callback(
|
||||
null,
|
||||
formatDNSValue(cached.value, {
|
||||
cached: true,
|
||||
error: err
|
||||
})
|
||||
);
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
@ -335,7 +468,7 @@ module.exports.resolveContent = (data, key, callback) => {
|
||||
callback(null, value);
|
||||
});
|
||||
} else if (/^https?:\/\//i.test(content.path || content.href)) {
|
||||
contentStream = fetch(content.path || content.href);
|
||||
contentStream = nmfetch(content.path || content.href);
|
||||
return resolveStream(contentStream, callback);
|
||||
} else if (/^data:/i.test(content.path || content.href)) {
|
||||
let parts = (content.path || content.href).match(/^data:((?:[^;]*;)*(?:[^,]*)),(.*)$/i);
|
||||
|
Reference in New Issue
Block a user