Kantoor.Karta.Routes (Kantoor v1.0.0)

Keeps Karta's routes for a domain in step with its mailboxes, aliases and catch-all.

Karta delivers a domain to Kantoor only through routes. Each mailbox address and each alias address therefore gets an exact route to the domain's endpoint. The * route is the domain's catch-all:

  • endpoint when the domain has a catch-all mailbox: mail for any other address is delivered to Kantoor, which routes it to that mailbox;
  • reject when the catch-all is off: Karta answers 550 while the sender is connected, so an unknown address is refused instead of accepted and silently dropped.

A disabled or suspended domain puts every route on hold: Karta keeps the mail, pushes nothing and refuses nothing. A mailbox that is disabled (but its domain is not) has its exact route set to reject, so its mail is refused too rather than pushed to a mailbox that cannot take it. A route at an address that is no longer a mailbox or alias of the domain (a deleted mailbox) is set to reject for the same reason.

Reversibility. Karta's mailbox interface can create and take over a route but not delete one, and a route in a non-delivering mode would lose its endpoint. reject routes are therefore written with spam_mode: hold, which Karta's changeset accepts and which keeps the endpoint on the route; a later sync can take the same route back to endpoint. The route never delivers in reject mode, so the spam mode has no effect on mail. The spam and DMARC protections of a delivering route stay on (spam_mode: mark, dmarc_reject: true, fail_closed: true).

Order and failure. Exact routes are written first, the * route last. If an exact route cannot be written, the * route is not moved to reject (that would refuse mail for an address whose own route is missing); the failure is returned and stored on the domain (routes_sync_error) for the admin screen and mix kantoor.routes.sync.

A local part Karta cannot route on its own (+, which it reads as a plus tag) gets no exact route; it is reported as a warning. Such a mailbox can only be reached through the catch-all while that is on.

Summary

Functions

Alias domains that depend on mailboxes of this domain; snapshot before deleting a mailbox.

What the last sync did, as the admin screen shows it.

Brings Karta's routes for one attached domain in step with Kantoor.

Syncs every attached domain. Returns [{name, result}]; the release task fails when any entry is an error.

Types

summary()

@type summary() :: %{
  created: non_neg_integer(),
  existing: non_neg_integer(),
  rejected: non_neg_integer(),
  star: atom(),
  warnings: [map()],
  failed: [map()]
}

Functions

dependent_domains(domain)

Alias domains that depend on mailboxes of this domain; snapshot before deleting a mailbox.

status(domain)

@spec status(Kantoor.Mailboxes.Domain.t()) :: :synced | :never | {:failed, String.t()}

What the last sync did, as the admin screen shows it.

sync(domain)

@spec sync(Kantoor.Mailboxes.Domain.t()) :: {:ok, summary()} | {:error, term()}

Brings Karta's routes for one attached domain in step with Kantoor.

{:ok, summary}, {:error, {:routes, summary}} (some route failed; what could be applied was), {:error, :not_attached} (no Karta route recorded), {:error, :not_configured} (Karta unset: nothing to do) or {:error, {:listing, reason}} (Karta's list could not be read; nothing was changed).

sync_all()

@spec sync_all() :: [{String.t(), {:ok, summary()} | {:error, term()}}]

Syncs every attached domain. Returns [{name, result}]; the release task fails when any entry is an error.