MCPcopy
hub / github.com/lissy93/web-check / mailConfigHandler

Function mailConfigHandler

api/mail-config.js:65–96  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

63};
64
65const mailConfigHandler = async (url) => {
66 const { hostname: domain } = parseTarget(url);
67 try {
68 const [mxRecords, rootTxt, dmarcTxt, bimiTxt, dkimResults] = await Promise.all([
69 dns.resolveMx(domain),
70 safeTxt(domain),
71 safeTxt(`_dmarc.${domain}`),
72 safeTxt(`default._bimi.${domain}`),
73 findDkim(domain),
74 ]);
75
76 // Collect email-relevant TXT records
77 const emailTxt = rootTxt.filter((r) => {
78 const s = r.join('').toLowerCase();
79 return s.startsWith('v=spf1');
80 });
81 dmarcTxt.forEach((r) => emailTxt.push(r));
82 bimiTxt.forEach((r) => emailTxt.push(r));
83 dkimResults.forEach(({ record }) => emailTxt.push(record));
84
85 return {
86 mxRecords,
87 txtRecords: emailTxt,
88 mailServices: detectProviders(mxRecords),
89 };
90 } catch (error) {
91 if (error.code === 'ENOTFOUND' || error.code === 'ENODATA') {
92 return { skipped: 'No mail server in use on this domain' };
93 }
94 return { error: `Mail config lookup failed: ${error.message}` };
95 }
96};
97
98export const handler = middleware(mailConfigHandler);
99export default handler;

Callers

nothing calls this directly

Calls 4

parseTargetFunction · 0.90
safeTxtFunction · 0.85
findDkimFunction · 0.85
detectProvidersFunction · 0.85

Tested by

no test coverage detected