diff --git a/src/mail-dns/mail-dns.ts b/src/mail-dns/mail-dns.ts index 32a72de..d3913b9 100644 --- a/src/mail-dns/mail-dns.ts +++ b/src/mail-dns/mail-dns.ts @@ -44,9 +44,18 @@ export function parseDkimPaste( 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 TXT value or Stalwart zone line.`, - ); + // Stalwart sometimes copies only the public key / p=… body. + const bare = text.replace(/^p=/i, '').replace(/\s+/g, ''); + if (/^[A-Za-z0-9+/=]+$/.test(bare) && bare.length >= 20) { + text = + expectedKind === 'ed25519' + ? `v=DKIM1; k=ed25519; h=sha256; p=${bare}` + : `v=DKIM1; k=rsa; h=sha256; p=${bare}`; + } else { + throw new Error( + `Could not find a v=DKIM1 value in the ${expectedKind} field. Paste the TXT value or Stalwart zone line.`, + ); + } } const kind = /k=ed25519/i.test(text)