otm-detector
Advanced tools
Comparing version 1.0.3 to 1.1.0
18
index.js
@@ -5,3 +5,7 @@ import dns from "node:dns/promises"; | ||
"mail.onetimemail.org", | ||
"mx.mail-data.net", | ||
]) | ||
const OTM_IPS = new Set([ | ||
"167.172.1.68" | ||
]) | ||
export const isOneTimeMail = async (domain, options = {}) => { | ||
@@ -11,3 +15,15 @@ const otmDns = options.dns || dns; | ||
const records = await otmDns.resolveMx(domain) | ||
return records.some((record) => OTM_HOSTS.has(record.exchange)) | ||
if (records.length === 0) { // this email is invalid, but we are not a validator | ||
return false | ||
} | ||
if (records.some((record) => OTM_HOSTS.has(record.exchange))) { | ||
return true | ||
} | ||
// check first record for new | ||
const mxHost = records[0].exchange | ||
const mxAddresses = await otmDns.resolve4(mxHost) | ||
if (mxAddresses.some((address) => OTM_IPS.has(address))) { | ||
return true | ||
} | ||
return false; | ||
} catch (e) { | ||
@@ -14,0 +30,0 @@ if (e.code === "ENOTFOUND") { |
@@ -12,2 +12,3 @@ import test from "node:test"; | ||
mx: ["smtp.google.com"], | ||
a: ["64.233.180.26", "142.251.163.27"], | ||
result: false, | ||
@@ -25,6 +26,12 @@ }, | ||
}, | ||
{ | ||
domain: "bad-ip.com", | ||
mx: ["mail.bad-ip.com"], | ||
result: true, | ||
a: ["167.172.1.68"], | ||
} | ||
]; | ||
for (const domain of domains) { | ||
test(`Check if ${domain.domain} has ${domain.mx} as MX`, async (t) => { | ||
test(`Check if ${domain.domain} has ${domain.mx}`, async (t) => { | ||
assert.equal( | ||
@@ -39,2 +46,8 @@ await isOneTimeMail(domain.domain, { | ||
}, | ||
resolve4: async (host) => { | ||
if (domain.a instanceof Error) { | ||
throw domain.a; | ||
} | ||
return domain.a; | ||
} | ||
}, | ||
@@ -41,0 +54,0 @@ }), |
{ | ||
"name": "otm-detector", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Detect one-time mail services, the new way", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
5506
7
88