Karta. Outbound. ReturnPath
(Karta v1.0.0)
VERP return paths: the envelope sender of each delivery names the recipient it is for, so a bounce that arrives later (to that address) tells which recipient of which message failed, without reading the bounce's text.
The local part is b, the recipient id (16 octets) and a tag (8 octets),
both in lower-case base32 without padding: 40 characters of a-z and
2-7, which survive mail systems that change the case of local parts.
The tag is an HMAC-SHA256 of the id, with a key derived from the vault
key, so nobody can make up return paths that Karta would believe: a
forged bounce for a guessed id fails parse/1. Tags made with a retired
vault key are still recognised, so a key rotation does not orphan the
bounces of mail in flight.
The domain is config :karta, Karta.Outbound, return_path_domain:
(KARTA_RETURN_PATH_DOMAIN); without one Karta sends with the message's
own envelope sender and receives no bounces this way. ours?/2 says
whether an address is in that domain, and verify/2 reads the recipient
id from an address there: a tag no vault key made is :invalid, and an
address whose recipient id is older than :max_age_days (default from
config :karta, Karta.Bounces) is :expired. The age comes from the id
itself (a version 7 UUID carries its creation time in milliseconds), so
the check needs no database; an id of another version has no age to
check.
Summary
Functions
The return path for the recipient recipient_id at domain.
The return path domain, or nil when none is configured.
How long a return path is believed, in days (KARTA_BOUNCE_MAX_AGE_DAYS).
True when address is in the return path domain (case and a final dot
do not matter). False without a configured domain.
The recipient id named by a return path (local@domain, or a bare local
part), or :error when the address is not one of ours: wrong form, or a
tag no vault key made. Case is ignored; the domain is not checked.
The recipient id named by a return path of ours, checked for age:
{:ok, id}, {:error, :invalid} for a wrong form or a tag no vault key
made, or {:error, :expired} for an address older than :max_age_days
(default 30). Options: :now (a DateTime) and
:max_age_days.
Functions
@spec address(Ecto.UUID.t(), String.t()) :: String.t()
The return path for the recipient recipient_id at domain.
@spec domain() :: String.t() | nil
The return path domain, or nil when none is configured.
@spec max_age_days() :: pos_integer()
How long a return path is believed, in days (KARTA_BOUNCE_MAX_AGE_DAYS).
True when address is in the return path domain (case and a final dot
do not matter). False without a configured domain.
@spec parse(String.t()) :: {:ok, Ecto.UUID.t()} | :error
The recipient id named by a return path (local@domain, or a bare local
part), or :error when the address is not one of ours: wrong form, or a
tag no vault key made. Case is ignored; the domain is not checked.
@spec verify(String.t(), keyword()) :: {:ok, Ecto.UUID.t()} | {:error, :invalid | :expired}
The recipient id named by a return path of ours, checked for age:
{:ok, id}, {:error, :invalid} for a wrong form or a tag no vault key
made, or {:error, :expired} for an address older than :max_age_days
(default 30). Options: :now (a DateTime) and
:max_age_days.