Accept bare DKIM public-key pastes without v=DKIM1 prefix.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-09-18 14:45:09 +03:30
co-authored by Cursor
parent 50b716f040
commit 94cb7eaa33
+9
View File
@@ -44,10 +44,19 @@ export function parseDkimPaste(
let text = (txtMatch ? txtMatch[0] : blob).trim(); let text = (txtMatch ? txtMatch[0] : blob).trim();
text = text.replace(/^"+|"+$/g, '').replace(/\s+/g, ' ').replace(/[.\s]+$/g, '').trim(); text = text.replace(/^"+|"+$/g, '').replace(/\s+/g, ' ').replace(/[.\s]+$/g, '').trim();
if (!/^v=DKIM1/i.test(text)) { if (!/^v=DKIM1/i.test(text)) {
// 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( throw new Error(
`Could not find a v=DKIM1 value in the ${expectedKind} field. Paste the TXT value or Stalwart zone line.`, `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) const kind = /k=ed25519/i.test(text)
? 'ed25519' ? 'ed25519'