Sovite.DMARC.Record (sovite v0.6.0)

Copy Markdown View Source

A DMARC policy record (RFC 7489 §6.3), as published in TXT at _dmarc.<domain>.

{:ok, record} = Sovite.DMARC.Record.parse("v=DMARC1; p=reject; rua=mailto:d@example.com")
record.p   #=> :reject
record.sp  #=> :reject

Parsing is lenient, as RFC 7489 §6.3 asks: unknown tags are ignored, and a known tag with an invalid value gets its default. After a successful parse no field is nil except psd:

  • sp defaults to p, and np (DMARCbis) to sp.
  • rua and ruf keep only mailto: URIs, each with the size limit from a !size suffix (RFC 7489 §6.4), or nil.
  • testing is the DMARCbis t=y flag, and psd the DMARCbis psd= tag: :yes, :no, or nil for u or absent.

Summary

Types

An identifier alignment mode.

A requested policy for failing mail.

t()

A report destination and the largest report it accepts, in bytes.

Functions

Returns whether a TXT record claims to be a DMARC record: its first tag is v=DMARC1. Records that do not are discarded during policy discovery.

Parses a DMARC record.

Types

mode()

@type mode() :: :relaxed | :strict

An identifier alignment mode.

policy()

@type policy() :: :none | :quarantine | :reject

A requested policy for failing mail.

t()

@type t() :: %Sovite.DMARC.Record{
  adkim: mode(),
  aspf: mode(),
  fo: String.t(),
  np: policy(),
  p: policy(),
  pct: 0..100,
  psd: :yes | :no | nil,
  ri: non_neg_integer(),
  rua: [uri()],
  ruf: [uri()],
  sp: policy(),
  testing: boolean()
}

uri()

@type uri() :: %{uri: String.t(), max_size: non_neg_integer() | nil}

A report destination and the largest report it accepts, in bytes.

Functions

dmarc?(text)

@spec dmarc?(String.t()) :: boolean()

Returns whether a TXT record claims to be a DMARC record: its first tag is v=DMARC1. Records that do not are discarded during policy discovery.

parse(text)

@spec parse(String.t()) :: {:ok, t()} | {:error, String.t()}

Parses a DMARC record.

Fails if v=DMARC1 is not the first tag, or if p is missing or invalid and there is no valid rua (RFC 7489 §6.6.3; with a valid rua, p is taken as none).