Add Email DNS upsert for Stalwart DKIM, MX, and SPF.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
6b8073f998
commit
6f1b13b6dc
@@ -0,0 +1,56 @@
|
||||
export const MAIL_IPV4 = '185.214.101.41';
|
||||
export const MAIL_HOSTNAME = 'mail.meshkee.com';
|
||||
export const MAIL_MX_PRIORITY = 10;
|
||||
export const MAIL_SPF = `v=spf1 ip4:${MAIL_IPV4} -all`;
|
||||
export const MAIL_DMARC = 'v=DMARC1; p=none';
|
||||
|
||||
export type MailDkimKey = {
|
||||
selector: string;
|
||||
text: string;
|
||||
};
|
||||
|
||||
export function parseDkimPaste(
|
||||
raw: string,
|
||||
expectedKind: 'ed25519' | 'rsa',
|
||||
): MailDkimKey {
|
||||
const input = raw.trim();
|
||||
if (!input) {
|
||||
throw new Error(`Paste the ${expectedKind} DKIM line from Stalwart.`);
|
||||
}
|
||||
|
||||
const quoted = [...input.matchAll(/"([^"]*)"/g)].map((match) => match[1]).join('');
|
||||
const compact = input.replace(/[()\n\r\t]+/g, ' ').replace(/\s+/g, ' ').trim();
|
||||
const blob = (quoted || compact).replace(/"\s+"/g, '');
|
||||
|
||||
const txtMatch = blob.match(/v=DKIM1[\s\S]*/i);
|
||||
let text = (txtMatch ? txtMatch[0] : blob).trim();
|
||||
text = text.replace(/^"+|"+$/g, '').replace(/\s+/g, ' ').replace(/[.\s]+$/g, '').trim();
|
||||
if (!/^v=DKIM1/i.test(text)) {
|
||||
throw new Error(
|
||||
`Could not find a v=DKIM1 value in the ${expectedKind} field. Paste the Stalwart zone line.`,
|
||||
);
|
||||
}
|
||||
|
||||
const kind = /k=ed25519/i.test(text)
|
||||
? 'ed25519'
|
||||
: /k=rsa/i.test(text)
|
||||
? 'rsa'
|
||||
: null;
|
||||
if (kind && kind !== expectedKind) {
|
||||
throw new Error(
|
||||
`That paste is ${kind} DKIM. Put it in the ${kind === 'ed25519' ? 'Ed25519' : 'RSA'} field.`,
|
||||
);
|
||||
}
|
||||
|
||||
const nameMatch = compact.match(/([a-z0-9][a-z0-9-]*)\._domainkey/i);
|
||||
if (!nameMatch) {
|
||||
throw new Error(
|
||||
'Include the selector name (for example v1-ed25519-20260831._domainkey) from the Stalwart zone file.',
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
selector: nameMatch[1].toLowerCase(),
|
||||
text,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user