Karta. Inbound
(Karta v1.0.0)
Receiving mail: a server's routes (Karta.Inbound.Route), which say
which addresses of its organisation's verified domains it receives, and
its endpoints (Karta.Inbound.Endpoint), where the mail goes.
Ownership. A route names a domain of the server's organisation that is verified; nobody else can route it, and a domain that loses its verification stops receiving. An endpoint and the routes that use it belong to the same server. Everything is found only through its own server, and an id that is not a UUID is simply not found.
In memory. The mx listener answers from the routes in memory
(Karta.Inbound.Directory); a change to a route reloads them on every
node.
Received mail (accept/2): the message is accepted together with a
Karta.Inbound.Delivery per recipient and the jobs that deliver them
(Karta.Inbound.Dispatcher, queue inbound): never acknowledged
without them. A delivery to an HTTP endpoint gets a job of its own; the
deliveries of the message to one SMTP or address endpoint share one job
(they are relayed, or forwarded, once).
Limits. A server has at most 1,000 routes and 100 endpoints.
Announcements. A route or an endpoint added, changed or removed is
announced on the server's topic (:routes, :endpoints), and what
becomes of a received message's deliveries when they are tried
(:inbound_deliveries, with the message's id), so pages that show them
read them again (Karta.Changes).
Configuration (config :karta, Karta.Inbound): allow_http (default
false) lets HTTP endpoints have http: URLs.
Summary
Functions
Accepts the pending incoming message message_id for routed, its
recipients with their routes as Karta.Inbound.Directory gives them, in
envelope order: a delivery per recipient (:pending for a route to an
endpoint; :accepted or :held for those modes, and :held for a
route the scan holds) and the jobs (one per delivery to an HTTP
endpoint, one per SMTP or address endpoint), in the transaction that
accepts the message. {:error, :not_pending} when it is not pending;
nothing is written then.
Adds an endpoint. Returns it with its secret (shown this once; nil for
kinds and formats without one: SMTP, addresses, Postal's format).
Adds a route. attrs name the domain by its name ("domain"), which
must be a verified domain of the server's organisation, and the endpoint
by its id, which must be an endpoint of the server.
Removes an endpoint; refused while a route uses it.
Removes a route.
The deliveries of a received message, in envelope order.
How many deliveries of each message are in each state:
%{message_id => %{status => count}} (messages without deliveries are
left out).
A delivery of the message, of the message's server, or nil.
An endpoint of the server, or nil.
A route of the server with its domain, or nil.
The job that delivers the delivery id (Karta.Inbound.Dispatcher).
The server's endpoints, oldest first.
The server's routes with their domains, by domain and local part.
Records the credential that registered a mailbox endpoint
(Karta.Kantoor.Attach). A key of the same server re-registering an
orphaned endpoint adopts it this way.
A page of the server's accepted incoming messages that match search,
newest first (Karta.Pager). Options: after, before and limit, as
for Karta.Pager.page/2. The search's delivery state asks for messages
with a delivery in that state; its status and tag fields (which the
received pages do not offer) do not apply.
Releases the held deliveries of the received message id of server:
they become :pending and are queued for the endpoint they were held
for, as if the message had just been accepted (Karta.Inbound.Dispatcher).
{:ok, count}, {:error, :not_found} (no such received message of this
server) or {:error, :not_held} (nothing of it is held).
Sends a delivery again: one that failed starts a new retry period; one
that waits is due now. {:error, :not_retryable} for one that was
delivered, stored only or held, which has nothing to try again.
Changes an endpoint (not its kind, nor an HTTP endpoint's format).
Changes a route's local part, mode, endpoint or plus addressing (not its domain).
Functions
@spec accept(Ecto.UUID.t(), [{String.t(), Karta.Inbound.Directory.route()}]) :: :ok | {:error, term()}
Accepts the pending incoming message message_id for routed, its
recipients with their routes as Karta.Inbound.Directory gives them, in
envelope order: a delivery per recipient (:pending for a route to an
endpoint; :accepted or :held for those modes, and :held for a
route the scan holds) and the jobs (one per delivery to an HTTP
endpoint, one per SMTP or address endpoint), in the transaction that
accepts the message. {:error, :not_pending} when it is not pending;
nothing is written then.
A route with status: :held (the mx listener's spam decision,
Karta.Scan) holds its delivery whatever its mode says.
@spec create_endpoint(Karta.Servers.Server.t(), map(), keyword()) :: {:ok, Karta.Inbound.Endpoint.t(), String.t() | nil} | {:error, Ecto.Changeset.t()}
Adds an endpoint. Returns it with its secret (shown this once; nil for
kinds and formats without one: SMTP, addresses, Postal's format).
Options for the mailbox interface (Karta.Kantoor.Attach): :credential_id
records the key that registered it, :kantoor marks it for Kantoor, and
:notify_only sets its push. They are not read from attrs, so no API
body can set ownership.
@spec create_route(Karta.Servers.Server.t(), map()) :: {:ok, Karta.Inbound.Route.t()} | {:error, Ecto.Changeset.t()}
Adds a route. attrs name the domain by its name ("domain"), which
must be a verified domain of the server's organisation, and the endpoint
by its id, which must be an endpoint of the server.
@spec delete_endpoint(Karta.Inbound.Endpoint.t()) :: {:ok, Karta.Inbound.Endpoint.t()} | {:error, Ecto.Changeset.t()}
Removes an endpoint; refused while a route uses it.
@spec delete_route(Karta.Inbound.Route.t()) :: {:ok, Karta.Inbound.Route.t()}
Removes a route.
@spec deliveries(Karta.Messages.Message.t()) :: [Karta.Inbound.Delivery.t()]
The deliveries of a received message, in envelope order.
@spec delivery_counts([Ecto.UUID.t()]) :: %{ required(Ecto.UUID.t()) => %{required(atom()) => pos_integer()} }
How many deliveries of each message are in each state:
%{message_id => %{status => count}} (messages without deliveries are
left out).
@spec get_delivery(Karta.Messages.Message.t(), term()) :: Karta.Inbound.Delivery.t() | nil
A delivery of the message, of the message's server, or nil.
@spec get_endpoint(Karta.Servers.Server.t(), term()) :: Karta.Inbound.Endpoint.t() | nil
An endpoint of the server, or nil.
@spec get_route(Karta.Servers.Server.t(), term()) :: Karta.Inbound.Route.t() | nil
A route of the server with its domain, or nil.
@spec job(Ecto.UUID.t(), keyword()) :: Ecto.Changeset.t()
The job that delivers the delivery id (Karta.Inbound.Dispatcher).
@spec list_endpoints(Karta.Servers.Server.t()) :: [Karta.Inbound.Endpoint.t()]
The server's endpoints, oldest first.
@spec list_routes(Karta.Servers.Server.t()) :: [Karta.Inbound.Route.t()]
The server's routes with their domains, by domain and local part.
@spec own_endpoint(Karta.Inbound.Endpoint.t(), %{id: Ecto.UUID.t()}) :: {:ok, Karta.Inbound.Endpoint.t()} | {:error, Ecto.Changeset.t()}
Records the credential that registered a mailbox endpoint
(Karta.Kantoor.Attach). A key of the same server re-registering an
orphaned endpoint adopts it this way.
@spec page_received(Karta.Servers.Server.t(), Karta.Messages.Search.t(), keyword()) :: Karta.Pager.Page.t()
A page of the server's accepted incoming messages that match search,
newest first (Karta.Pager). Options: after, before and limit, as
for Karta.Pager.page/2. The search's delivery state asks for messages
with a delivery in that state; its status and tag fields (which the
received pages do not offer) do not apply.
@spec release(Karta.Servers.Server.t(), term()) :: {:ok, non_neg_integer()} | {:error, :not_found | :not_held}
Releases the held deliveries of the received message id of server:
they become :pending and are queued for the endpoint they were held
for, as if the message had just been accepted (Karta.Inbound.Dispatcher).
{:ok, count}, {:error, :not_found} (no such received message of this
server) or {:error, :not_held} (nothing of it is held).
Only a :held delivery moves, in one conditional statement, so a second
release at the same time releases nothing.
@spec retry_delivery(Karta.Inbound.Delivery.t()) :: {:ok, Karta.Inbound.Delivery.t()} | {:error, :not_retryable}
Sends a delivery again: one that failed starts a new retry period; one
that waits is due now. {:error, :not_retryable} for one that was
delivered, stored only or held, which has nothing to try again.
@spec update_endpoint(Karta.Inbound.Endpoint.t(), map()) :: {:ok, Karta.Inbound.Endpoint.t()} | {:error, Ecto.Changeset.t()}
Changes an endpoint (not its kind, nor an HTTP endpoint's format).
@spec update_route(Karta.Inbound.Route.t(), map()) :: {:ok, Karta.Inbound.Route.t()} | {:error, Ecto.Changeset.t()}
Changes a route's local part, mode, endpoint or plus addressing (not its domain).