Kantoor.Identities (Kantoor v1.0.0)

Sending identities (name, address, reply-to, signature) of the signed-in user.

Authorisation is the compose rule: an identity may use the address of a mailbox the user may open (Kantoor.Accounts.list_mailboxes/1: the attached mailboxes, every mailbox for an admin), or an alias of such a mailbox (Kantoor.Aliases). The rule is checked again at send time (for_send/2), so detaching a mailbox, or deleting its alias, disables the identities on it.

Every function takes the scope first and answers {:error, :not_found} for an identity that is not the scope's own, so existence is not revealed. A user has at most one default identity; the first identity created becomes it, and deleting the default promotes the oldest remaining one.

Attributes (string or atom keys): "address" (required on create; picks the mailbox), "name", "reply_to", "signature_text", "signature_html" (sanitised on save, without remote content) and "is_default".

Summary

Functions

The addresses the scope may create an identity for: the addresses of the mailboxes it may send as, and the aliases of those mailboxes. A mailbox with only the read role is not offered: an identity that cannot send is not one.

Creates an identity. The first one of a user becomes the default.

The default identity, or nil when the user has none.

Deletes an identity; when it was the default, the oldest remaining one becomes it.

The identity and its mailbox for sending, or {:error, :not_found} when the identity is not the scope's, the scope may no longer open its mailbox, or the identity's address (a mailbox address or an alias of it) no longer resolves to that mailbox.

One of the scope's identities.

The scope's identities, default first, then by address.

Makes an identity the user's default.

Updates name, reply-to, signatures and, with "address", the address (the same rule as on create). "is_default" => true makes it the default.

Types

error()

@type error() :: :not_found | :limit | {:invalid, %{required(atom()) => String.t()}}

Functions

available_addresses(scope)

@spec available_addresses(Kantoor.Accounts.Scope.t() | nil) :: [String.t()]

The addresses the scope may create an identity for: the addresses of the mailboxes it may send as, and the aliases of those mailboxes. A mailbox with only the read role is not offered: an identity that cannot send is not one.

create(scope, attrs)

@spec create(Kantoor.Accounts.Scope.t() | nil, map()) ::
  {:ok, Kantoor.Identities.Identity.t()} | {:error, error()}

Creates an identity. The first one of a user becomes the default.

default(scope)

@spec default(Kantoor.Accounts.Scope.t() | nil) ::
  Kantoor.Identities.Identity.t() | nil

The default identity, or nil when the user has none.

delete(scope, id)

@spec delete(Kantoor.Accounts.Scope.t() | nil, term()) :: :ok | {:error, :not_found}

Deletes an identity; when it was the default, the oldest remaining one becomes it.

for_send(scope, id)

@spec for_send(Kantoor.Accounts.Scope.t() | nil, term()) ::
  {:ok, Kantoor.Identities.Identity.t(), Kantoor.Mailboxes.Mailbox.t()}
  | {:error, :not_found}

The identity and its mailbox for sending, or {:error, :not_found} when the identity is not the scope's, the scope may no longer open its mailbox, or the identity's address (a mailbox address or an alias of it) no longer resolves to that mailbox.

get(arg1, id)

@spec get(Kantoor.Accounts.Scope.t() | nil, term()) ::
  {:ok, Kantoor.Identities.Identity.t()} | {:error, :not_found}

One of the scope's identities.

list(arg1)

The scope's identities, default first, then by address.

set_default(scope, id)

@spec set_default(Kantoor.Accounts.Scope.t() | nil, term()) ::
  {:ok, Kantoor.Identities.Identity.t()} | {:error, :not_found}

Makes an identity the user's default.

update(scope, id, attrs)

@spec update(Kantoor.Accounts.Scope.t() | nil, term(), map()) ::
  {:ok, Kantoor.Identities.Identity.t()} | {:error, error()}

Updates name, reply-to, signatures and, with "address", the address (the same rule as on create). "is_default" => true makes it the default.