mail: dnsbl can give empty records
This commit is contained in:
10
src/mail.js
10
src/mail.js
@@ -501,6 +501,7 @@ const RBL_LIST = [
|
||||
}
|
||||
];
|
||||
|
||||
// https://tools.ietf.org/html/rfc5782
|
||||
async function checkRbl(type, mailDomain) {
|
||||
assert.strictEqual(typeof type, 'string');
|
||||
assert.strictEqual(typeof mailDomain, 'object');
|
||||
@@ -516,22 +517,21 @@ async function checkRbl(type, mailDomain) {
|
||||
|
||||
const flippedIp = type === 'ipv4' ? ip.split('.').reverse().join('.') : reverseIPv6(ip);
|
||||
|
||||
// https://tools.ietf.org/html/rfc5782
|
||||
const blockedServers = [];
|
||||
for (const rblServer of RBL_LIST) {
|
||||
if (type === 'ipv6' && rblServer[type] !== true) continue; // all support ipv4
|
||||
|
||||
const [error, records] = await safe(dig.resolve(`${flippedIp}.${rblServer.dns}`, 'A', DNS_OPTIONS));
|
||||
if (error || !records) continue; // not listed
|
||||
if (error || records.length === 0) continue; // not listed
|
||||
|
||||
debug(`checkRbl: ${domain} flippedIp: ${flippedIp} is in the blocklist of ${rblServer.dns}`);
|
||||
debug(`checkRbl (${domain}) flippedIp: ${flippedIp} is in the blocklist of ${rblServer.dns}: ${JSON.stringify(records)}`);
|
||||
|
||||
const result = Object.assign({}, rblServer);
|
||||
|
||||
const [error2, txtRecords] = await safe(dig.resolve(`${flippedIp}.${rblServer.dns}`, 'TXT', DNS_OPTIONS));
|
||||
result.txtRecords = error2 || !txtRecords ? 'No TXT record' : txtRecords.map(x => x.join(''));
|
||||
|
||||
debug(`checkRbl: ${domain} error: ${error2?.message || null} txtRecords: ${JSON.stringify(txtRecords)}`);
|
||||
debug(`checkRbl (${domain}) error: ${error2?.message || null} txtRecords: ${JSON.stringify(txtRecords)}`);
|
||||
|
||||
blockedServers.push(result);
|
||||
}
|
||||
@@ -540,7 +540,7 @@ async function checkRbl(type, mailDomain) {
|
||||
status: blockedServers.length === 0 ? 'passed' : 'failed',
|
||||
ip,
|
||||
servers: blockedServers,
|
||||
message: `Check using "host ${flippedIp} 127.0.0.150"`
|
||||
message: ''
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user