kMarc
Collects the DMARC aggregate reports piling up in a mailbox and shows which IPs send mail as your domain, and whether receivers saw them pass.
source (opens in new tab)The problem
If you run your own mail, DMARC aggregate reports (summaries mail receivers send about messages that used your domain) are how the rest of the internet tells you whether your SPF (a DNS record listing the hosts allowed to send mail for a domain) and DKIM (a signature on outgoing mail that receivers verify against a key in DNS) hold up. They arrive as XML, zipped or gzipped into an attachment, in a mailbox nobody reads (except kMarc, now). kMarc pulls them over IMAP and turns them into per-domain reports you can read in a terminal.
Architecture
kMarc is a single-package Bun/TypeScript CLI with five commands: sync,
watch, summary, report, and export. Each mail source is its own config
file describing one mailbox. sync compares the server's UIDs against SQLite,
keyed by source, mailbox, UIDVALIDITY (a number the IMAP server changes when a mailbox's message IDs start over), and UID, so a rebuilt mailbox can't make
new messages look already imported, and fetches only what's new. Watch mode
uses IMAP IDLE (an IMAP command that lets the server notify a waiting client of new mail) where the server offers it, raced against the polling interval
so a silent server can't stall it. A failing source is logged while the others
keep syncing, and after a failed cycle watch doubles its wait, up to 16 times
the poll interval and never more than 15 minutes. A malformed message is
counted as failed and skipped, and the rest of the queue keeps going.
Everything is kept twice. On disk, kMarc stores each raw RFC 822 (the standard format for a single email message) message under
its source, mailbox, UIDVALIDITY, and UID, and each decompressed report
attachment once per SHA-256 checksum. Directories are created 0700, files
0600, and every file is fsynced before its database row commits. The second
copy is a normalized SQLite database for querying. Reporters sometimes resend
a report with byte-level differences, so aggregate reports are also
deduplicated by reporter organization plus report ID, the identifier RFC 7489
provides for ignoring duplicates. Parsing has hard caps: 50 MiB per message,
32 attachments, 25 MiB per attachment and per decompressed report, 16 ZIP
entries, and 100,000 records per report, because a mailbox that accepts
reports from the whole internet is untrusted input.
For report, kMarc also looks up the live DMARC policy (exact domain, then
organizational domain, then RFC 9091 public suffix (a suffix under which the public registers domains, like co.uk) discovery for suffixes you
list as trusted) and checks the live SPF record for each domain's ten
highest-volume source IPs. It shows which SPF mechanism authorizes them, a
risk level from likely legitimate to likely spoofed, and any policy overrides
the receiver applied. Terminals 80 columns or wider get tables; narrower ones
get one stacked record per row, so no security-relevant field gets dropped.
Terminal output is colored and falls back to plain text when piped or under
NO_COLOR; --write saves Markdown or a standalone responsive HTML page.
export writes JSON or CSV, and builds compile to standalone binaries for
Linux, Windows, and macOS.
Boundaries
kMarc reads reports about your mail; it doesn't touch your mail flow. Deleting processed messages from the remote mailbox is off by default and set per source. Once enabled, it deletes newly stored messages and previously recorded UIDs, including malformed aggregate attachments kept locally for diagnosis, while leaving unrecognized mail on the server. kMarc is deliberately a local administrator tool, not a hosted service: credentials, raw reports, and source IPs stay in local files and SQLite, protected by file permissions, and kMarc warns when a host config holding a password is readable by other users. It shows which senders fail alignment (whether the domain SPF or DKIM verified matches the visible From domain) and which IPs your current SPF record doesn't authorize; fixing the DNS records is still your job.