-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
27 lines (26 loc) · 865 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import dns from "node:dns/promises";
import { OTM_HOSTS, OTM_IPS } from './blocklist.js';
export const isOneTimeMail = async (domain, options = {}) => {
const otmDns = options.dns || dns;
try {
const records = await otmDns.resolveMx(domain)
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) {
if (e.code === "ENOTFOUND") {
return false
}
throw e
}
};