Kantoor.Autoconfig (Kantoor v1.0.0)

Mail client auto-configuration in the Mozilla "autoconfig" format (config-v1.1.xml), read by Thunderbird, GNOME Evolution, KMail, K-9 and others.

The host names and ports clients are told are the PUBLIC ones (what the reverse proxy or TCP proxy exposes), not the container's listener ports, so they come from configuration (config :kantoor, :autoconfig, filled from KANTOOR_AUTOCONFIG_* in config/runtime.exs, documented in docs/deploy.md):

  • :imap_host, :imap_port, :imap_socket (:ssl or :starttls)
  • :pop3_host, :pop3_port, :pop3_socket (offered only when a port is set)
  • :smtp_host, :smtp_port, :smtp_socket, optional :smtp_starttls_port

Defaults: the host is the endpoint's public host (PHX_HOST); IMAP is offered when the IMAP listener is enabled (config :kantoor, :imap) or an IMAP port is configured here (default 993, implicit TLS). The SMTP entry falls back to the submission server's own keys (config :kantoor, :smtp: :host, :tls_port, :port) and is left out when neither is configured. Nothing is guessed.

The user name is always the full email address (%EMAILADDRESS%): that is the login Kantoor.AppPasswords accepts. The password is an app password.

Summary

Functions

The public base URL of the web endpoint, without a trailing slash.

The config-v1.1.xml document for email (a string or nil). Returns :none when no mail server is configured to advertise.

Where CalDAV and CardDAV live: the web endpoint's public host and port (DAV is served by this same application under /dav).

The servers to show in the webmail's own client settings ("Mail apps").

The servers to advertise, in the order IMAP, POP3, SMTP.

Validates the SHAPE of an email address from a request (not whether an account exists): at most 254 bytes, a conservative local part, a host-name-shaped domain. Returns {:ok, address} (domain lower-cased) or :error. Used by every discovery answer before the address is echoed anywhere.

Escapes text for XML (and plist) element content and attribute values.

Types

server()

@type server() :: %{
  type: :imap | :pop3 | :smtp,
  host: String.t(),
  port: pos_integer(),
  socket: :ssl | :starttls
}

Functions

base_url()

@spec base_url() :: String.t()

The public base URL of the web endpoint, without a trailing slash.

config_xml(email, overrides \\ [])

@spec config_xml(String.t() | nil, keyword()) :: {:ok, String.t()} | :none

The config-v1.1.xml document for email (a string or nil). Returns :none when no mail server is configured to advertise.

dav()

@spec dav() :: %{host: String.t(), port: pos_integer(), ssl: boolean()}

Where CalDAV and CardDAV live: the web endpoint's public host and port (DAV is served by this same application under /dav).

manual_servers()

@spec manual_servers() :: [server()]

The servers to show in the webmail's own client settings ("Mail apps").

servers/1 is what the public autoconfig document advertises. This one also names a listener that is enabled but deliberately not advertised there: POP3 is offered on its standard implicit-TLS port 995 (or :pop3_port when set), because the Mozilla format has no comfortable way to offer it beside IMAP. The other entries are the same as servers/1, so the page and the discovery document never disagree about a host or a port.

The host and port are the public ones, from config :kantoor, :autoconfig, exactly as for servers/1.

servers(overrides \\ [])

@spec servers(keyword()) :: [server()]

The servers to advertise, in the order IMAP, POP3, SMTP.

valid_address(email)

@spec valid_address(term()) :: {:ok, String.t()} | :error

Validates the SHAPE of an email address from a request (not whether an account exists): at most 254 bytes, a conservative local part, a host-name-shaped domain. Returns {:ok, address} (domain lower-cased) or :error. Used by every discovery answer before the address is echoed anywhere.

xml_escape(text)

@spec xml_escape(term()) :: String.t()

Escapes text for XML (and plist) element content and attribute values.