Karta.MTASTS.Policy (Karta v1.0.0)

An MTA-STS policy (RFC 8461 §3.2) and the check of an MX host against it (§4.1).

A policy is lines of key: value (LF or CRLF line endings):

version: STSv1
mode: enforce
mx: mail.example.com
mx: *.example.net
max_age: 1209600

version (STSv1), mode (enforce, testing or none) and max_age (seconds, at most 31,557,600; a larger value is lowered to it) are required; mx may repeat and is required unless the mode is none. Of a repeated field other than mx the first counts; unknown fields are ignored; empty lines are allowed. A line that is not a key: value pair, a value that is not printable ASCII, or an mx that is not a host name (optionally *. and a host name) makes the whole policy invalid.

id is the version the domain's TXT record announced when the policy was fetched (Karta.MTASTS.TXT); text the policy as fetched.

Summary

Functions

True when host (an MX host name) matches one of the policy's mx patterns: the same name, ignoring case and a final dot, or for *.example.com any name of exactly one more label (mx1.example.com, not example.com or a.b.example.com).

The longest max_age honoured, in seconds (one year).

Parses a policy. {:error, reason} says what is wrong, in words.

Types

mode()

@type mode() :: :enforce | :testing | :none

t()

@type t() :: %Karta.MTASTS.Policy{
  id: String.t() | nil,
  max_age: non_neg_integer(),
  mode: mode(),
  mx: [String.t()],
  text: String.t()
}

Functions

matches?(policy, host)

@spec matches?(t(), String.t()) :: boolean()

True when host (an MX host name) matches one of the policy's mx patterns: the same name, ignoring case and a final dot, or for *.example.com any name of exactly one more label (mx1.example.com, not example.com or a.b.example.com).

max_age_limit()

@spec max_age_limit() :: pos_integer()

The longest max_age honoured, in seconds (one year).

parse(text)

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

Parses a policy. {:error, reason} says what is wrong, in words.