Something went wrong. Try again.
DMARC (RFC 7489) for Zig: the record grammar, identifier alignment, and policy discovery by DNS tree walk rather than a public suffix list.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869// SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! A small tool for looking at DMARC records.//!//! ```//! dmarc parse <record>//! ```
const std = @import("std");const Io = std.Io;const dmarc = @import("dmarc");
pub fn main(init: std.process.Init) !void { const gpa = init.arena.allocator(); const io = init.io; const args = try init.minimal.args.toSlice(gpa);
var out_buffer: [4096]u8 = undefined; var out = Io.File.stdout().writer(io, &out_buffer); const w = &out.interface; defer w.flush() catch {};
if (args.len < 3 or !std.mem.eql(u8, args[1], "parse")) { try w.writeAll( \\usage: \\ dmarc parse <record> take a record apart without asking anything \\ ); return; } try parse(w, args[2]);}
fn parse(w: *Io.Writer, text: []const u8) !void { const record = dmarc.Record.parse(text) catch |err| { try w.print("no policy here: {t}\n", .{err}); switch (err) { // The distinction worth printing, because the two look alike // and mean opposite things to a receiver. error.NotDmarc => try w.writeAll( " this text is not a DMARC record, so the domain has no policy\n", ), error.NoPolicy => try w.writeAll( " a DMARC record with no usable p= and no rua= to report to\n", ), } return; };
try w.print(" policy {t}{s}\n", .{ record.policy, if (record.assumed_policy) " (assumed: the record had no usable p=)" else "", }); if (record.subdomain_policy) |policy| { try w.print(" subdomains {t}\n", .{policy}); } else { try w.print(" subdomains {t} (inherited)\n", .{record.policy}); } try w.print(" alignment dkim {t}, spf {t}\n", .{ record.dkim_alignment, record.spf_alignment, }); if (record.percent != 100) try w.print(" applied to {d}%\n", .{record.percent}); if (record.aggregate_reports) |uris| try w.print(" aggregate {s}\n", .{uris}); if (record.failure_reports) |uris| try w.print(" failure {s}\n", .{uris}); try w.print(" interval {d}s\n", .{record.report_interval});}