Skip to content
  1. Docs
  2. Apps
  3. Developers

Mail internals

How Mail talks IMAP and SMTP, keeps local state, pushes new mail, discovers servers and renders HTML safely.

This page is a map of Mail's source for contributors: where IMAP and SMTP live, how local state is kept consistent with the server, and how HTML mail is rendered. For using Mail, see Mail.

Transport

Mail's network layer lives in src/backend/.

ModuleOwns
config.rsvalidated account configuration: protocol, servers, ports, encryption, authentication method
discovery.rsfinding server settings from an email address
curl_backend.rsIMAP and SMTP over libcurl, with bounded I/O and cancellation
curl_backend/transport.rsIMAP command execution and SMTP submission
curl_backend/fetch.rsUID paging and fetch-response parsing
curl_backend/mime.rsMIME parsing
curl_backend/operations.rsthe backend pool, sync, and reconciliation of local mutations
curl_backend/oauth.rsbrowser sign-in for native apps (RFC 8252) and XOAUTH2
inbox_watch.rspush notification of new mail through IMAP IDLE
unsubscribe.rsone-click unsubscribe (RFC 8058 POST, or mailto:)

Incoming mail uses IMAP over implicit TLS. Outgoing mail uses SMTP with implicit TLS or STARTTLS. Authentication can be a password, LOGIN, or OAuth 2.0.

Server discovery

When a user enters an address, Mail looks up settings in this order: the domain's autoconfiguration, DNS SRV records, the Mozilla ISP database, and finally a match on the domain's MX provider. If none succeeds, the user fills in the server step by hand.

Push mail

inbox_watch.rs runs one worker per account holding an IMAP IDLE connection on the Inbox. The worker blocks in poll(2) between server pushes, renewals and retry backoffs, so a watched Inbox costs no wake-ups. The watch only says when something changed; the app still syncs through its ordinary operation queue. A server without IDLE, or a refused login, ends the watch and periodic sync carries on alone.

Local state

Mail works from local state: counts and search describe locally cached mail, with bounded server search and retrieval of older messages where available.

  • src/local_state.rs holds offline messages and pending IMAP mutations. Mutations are confirmed by UID and generation, so a stale completion cannot overwrite newer state.
  • src/preferences.rs persists rules, privacy choices and the sidebar layout.
  • src/attachment_store.rs takes custody of attachments: files from the chooser or a drop are copied into private staging and size-checked before they become part of a draft.
  • Drafts, the outbox and scheduled messages (src/schedule.rs) persist across restarts. Closing waits for pending persistence and offers recovery after a failed save.

Credentials never reach these files. Passwords and OAuth tokens live in the Secret Service.

Conversations are threaded by Message-ID, In-Reply-To and References; the subject is only used to repair broken chains (src/model/thread.rs). Search operators are parsed in src/model/search.rs, and rules in src/model/rules.rs.

HTML rendering

HTML mail goes through two stages.

  1. Sanitizing. Message HTML is cleaned with the ammonia sanitizer. src/model/html.rs also produces a text projection used for search and as a fallback.
  2. Rendering. src/mail_html.rs passes the sanitized document to the message-view widget from the pinned WebKit Rust adapter. The shipped build renders with Blitz. mail_html/dark_mode.rs adapts colours for dark mode, and src/html_viewport.rs reports visibility and width.

Remote images require consent, and external links require confirmation. While switching messages, the reader keeps the last visible preview until the replacement has painted; that pending preview accepts no input or link activation. If the engine cannot start, Mail shows the sanitized text and stops retrying in that process; src/html_view.rs is the non-networking fallback.

The released build leaves the native WPE backend disabled. Use the Mail source and build instructions for the supported configuration.

Assistants

With the optional center feature, src/center.rs registers Mail's functions and src/background.rs runs the windowless worker. The functions are list_mailboxes, list_messages, select_mailbox, prepare_send and review_status. None of them sends mail: prepare_send presents a composer, and only a person's confirmation sends it. See Agent background mode.

OAuth client IDs

Browser sign-in needs a registered client ID, supplied at build or run time:

VariablePurpose
ENZUI_MAIL_GOOGLE_CLIENT_IDGoogle client ID
ENZUI_MAIL_GOOGLE_CLIENT_SECRETGoogle desktop client secret
ENZUI_MAIL_MICROSOFT_CLIENT_IDMicrosoft client ID

The repository bundles no provider credentials.