Karta.Reports.DMARC.Aggregate (Karta v1.0.0)

Reading a DMARC aggregate report (RFC 7489 §7.2 and Appendix C): the XML a receiving server sends the domain owner about the mail it received that claimed to be from that domain.

A report says who reported (org_name, email, report_id), the period it covers, the policy the domain published, and one record per source address: how many messages came from it, what the receiver did with them (disposition), whether DKIM and SPF passed for the domain (dkim, spf), the identifiers the messages carried, and the authentication results behind the verdict.

Parsing is reading hostile input. A report arrives over SMTP from anyone who can reach the address. parse/2 uses OTP's SAX parser with entity declarations refused, external entities never read and undeclared references an error, so a report can name no DTD, no entity and no file or URL outside itself; a document type declaration and a processing instruction are refused by name. Nothing is looked up while parsing.

Every size is bounded: the document (32 MiB), its elements (2,000,000), its records (50,000), the reasons and authentication results of a record (10 and 100) and the text of a field (1,024 bytes; longer text is cut). The element and record limits end the parse as soon as they are passed.

What the report says is data, never authority: the domains in it are compared with the domains Karta serves, but nothing in a report makes Karta accept, refuse, sign or verify anything.

Returns {:ok, report} with :org_name, :email, :extra_contact_info, :report_id, :date_begin, :date_end, :errors, :policy and :records; or {:error, reason}: :too_large (the document, its elements or a record's text), :too_many_records, :unsupported_version, :doctype, :processing_instruction, :invalid_xml or :invalid_report (a required field is missing or cannot be read).

Summary

Functions

Reads one aggregate report. Options: :max_bytes, :max_elements and :max_records (the defaults above; tests make them small).

Types

entry()

@type entry() :: %{
  source_ip: String.t(),
  count: non_neg_integer(),
  disposition: String.t(),
  dkim: String.t(),
  spf: String.t(),
  reasons: [%{type: String.t() | nil, comment: String.t() | nil}],
  header_from: String.t(),
  envelope_from: String.t() | nil,
  envelope_to: String.t() | nil,
  auth_dkim: [map()],
  auth_spf: [map()]
}

t()

@type t() :: %{
  version: String.t(),
  org_name: String.t(),
  email: String.t(),
  extra_contact_info: String.t() | nil,
  report_id: String.t(),
  date_begin: DateTime.t(),
  date_end: DateTime.t(),
  errors: [String.t()],
  policy: %{
    domain: String.t(),
    adkim: String.t() | nil,
    aspf: String.t() | nil,
    p: String.t(),
    sp: String.t() | nil,
    pct: non_neg_integer() | nil,
    fo: String.t() | nil
  },
  records: [entry()]
}

Functions

parse(xml, opts \\ [])

@spec parse(binary(), keyword()) :: {:ok, t()} | {:error, atom()}

Reads one aggregate report. Options: :max_bytes, :max_elements and :max_records (the defaults above; tests make them small).