Karta. Mail. Authorisation
(Karta v1.0.0)
Checks that a message names only permitted domains as its author: every mailbox in From and the Sender, if there is one.
The decision is made on addresses parsed by Karta.Mail.Address and
compared in ASCII form (Karta.Mail.Punycode.to_ascii/1), never on the
raw header text. A message is refused when:
- it has no From field or more than one (RFC 5322 §3.6 allows exactly one);
- From is not a valid mailbox list (a group is refused too);
- it has more than one Sender field, or Sender is not exactly one mailbox;
- From lists several mailboxes but there is no Sender (RFC 5322 §3.6.2);
- any of those mailboxes has a domain that is not permitted, or that has no unambiguous ASCII form (domain literals included).
allowed is a list of domains (compared exactly, after conversion to
ASCII form; subdomains are not implied) or a function that receives each
domain in ASCII form and returns a boolean.
Summary
Types
@type reason() :: :missing_from | :multiple_from | :invalid_from | :multiple_sender | :invalid_sender | :sender_required | {:domain_not_allowed, String.t()}
Functions
@spec check_from([Karta.Mail.Header.t()], [String.t()] | (String.t() -> boolean())) :: :ok | {:error, reason()}