Parse a DMARC record
Split a published DMARC TXT value into its tags.
function parseDmarc(record) { return Object.fromEntries(record.split(';').map(tag => tag.trim()).filter(Boolean).map(tag => [tag.slice(0, tag.indexOf('=')).trim().toLowerCase(), tag.slice(tag.indexOf('=') + 1).trim()])); }
Input & expected output
Input
"v=DMARC1; p=quarantine; rua=mailto:[email protected]; adkim=s"Expected output
{
"v": "DMARC1",
"p": "quarantine",
"rua": "mailto:[email protected]",
"adkim": "s"
}The edge case
Input
"v=DMARC1;p=reject;"Expected output
{
"v": "DMARC1",
"p": "reject"
}Know the limits
- Tag names are lowercased; values are kept as published. Unknown tags are returned, not validated.
- The lab requires v=DMARC1 as the first tag and = in every tag, as receivers discard other records (RFC 7489). Check that p is present: it is the policy receivers apply.
The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.
Source & maintenance
Written by Oveyon for this edition of 1loc.dev; it is not part of the original collection. Copyright (c) 2026 Oveyon. MIT licensed.
The function above is the implementation the lab runs and the tests exercise. Read the license.
Keep exploring
- Convert an email domain to punycode — Keep the local part and convert an international domain to its ASCII xn-- form.
- Get the domain of an email address — Take the part after the last @ and lowercase it, for domain checks and grouping.
- Mask an email address for logs — Keep the first character and the domain; hide the rest of the local part.