Karta.Auth.SPF (Karta v1.0.0)

SPF (RFC 7208): whether a domain authorises the client that sent a message, by its check_host() function (§4).

  • mail_from/4 checks the MAIL FROM identity: the sender's domain, or for the null sender postmaster@ the HELO name (§2.4).
  • helo/3 checks the HELO identity (§2.3).
  • check_host/4 is the function itself.

Every mechanism (all, include, a, mx, ptr, ip4, ip6, exists), both modifiers (redirect, exp) and every macro are implemented, and checked against the SPF project's RFC 7208 test suite.

Limits (§4.6.4), so that a record cannot make Karta do unbounded work: at most 10 terms that look up DNS (include, a, mx, ptr, exists, redirect; the 11th is a permerror), at most 2 of their lookups that find nothing (permerror), at most 10 MX records per mx (more is a permerror) and 10 PTR names per ptr or %{p} (the rest are ignored). Each lookup goes through Karta.DNS with its cache and the resolver's own timeouts; with :deadline the whole check also stops at that time, with a temperror.

Results are Karta.Auth.SPF.Results. A DNS error is a temperror, never a negative answer.

Options:

  • :dns - options for Karta.DNS.lookup/3 (:resolver, :cache);
  • :helo - the HELO name, for %{h} (mail_from/4 and helo/3 set it);
  • :receiver - the receiving host's name, for %{r} (default unknown);
  • :now - Unix seconds, for %{t};
  • :deadline - a System.monotonic_time(:millisecond) after which no lookup starts (default: no bound beyond the limits);
  • :explain - look up the explanation of a fail (default false); :default_explanation is used when there is none (default nil);
  • :static - a check of a domain's configuration rather than of a message: a macro or ptr that evaluation reaches gives :unknown (Karta.IPPools.SPF).

Summary

Functions

check_host(<ip>, <domain>, <sender>) (RFC 7208 §4): the result for ip sending as sender (local@domain), with the record of domain.

Checks the HELO identity: postmaster@<helo> against the HELO name's record.

Checks the MAIL FROM identity: sender is the envelope sender, or nil (or "") for the null reverse path, in which case postmaster@<helo> is checked.

Functions

check_host(ip, domain, sender, opts \\ [])

check_host(<ip>, <domain>, <sender>) (RFC 7208 §4): the result for ip sending as sender (local@domain), with the record of domain.

helo(ip, helo, opts \\ [])

@spec helo(:inet.ip_address(), String.t() | nil, keyword()) ::
  Karta.Auth.SPF.Result.t()

Checks the HELO identity: postmaster@<helo> against the HELO name's record.

mail_from(ip, sender, helo, opts \\ [])

@spec mail_from(:inet.ip_address(), String.t() | nil, String.t() | nil, keyword()) ::
  Karta.Auth.SPF.Result.t()

Checks the MAIL FROM identity: sender is the envelope sender, or nil (or "") for the null reverse path, in which case postmaster@<helo> is checked.