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/.
| Module | Owns |
|---|---|
config.rs | validated account configuration: protocol, servers, ports, encryption, authentication method |
discovery.rs | finding server settings from an email address |
curl_backend.rs | IMAP and SMTP over libcurl, with bounded I/O and cancellation |
curl_backend/transport.rs | IMAP command execution and SMTP submission |
curl_backend/fetch.rs | UID paging and fetch-response parsing |
curl_backend/mime.rs | MIME parsing |
curl_backend/operations.rs | the backend pool, sync, and reconciliation of local mutations |
curl_backend/oauth.rs | browser sign-in for native apps (RFC 8252) and XOAUTH2 |
inbox_watch.rs | push notification of new mail through IMAP IDLE |
unsubscribe.rs | one-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.rsholds offline messages and pending IMAP mutations. Mutations are confirmed by UID and generation, so a stale completion cannot overwrite newer state.src/preferences.rspersists rules, privacy choices and the sidebar layout.src/attachment_store.rstakes 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.
- Sanitizing. Message HTML is cleaned with the
ammoniasanitizer.src/model/html.rsalso produces a text projection used for search and as a fallback. - Rendering.
src/mail_html.rspasses the sanitized document to the message-view widget from the pinned WebKit Rust adapter. The shipped build renders with Blitz.mail_html/dark_mode.rsadapts colours for dark mode, andsrc/html_viewport.rsreports 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:
| Variable | Purpose |
|---|---|
ENZUI_MAIL_GOOGLE_CLIENT_ID | Google client ID |
ENZUI_MAIL_GOOGLE_CLIENT_SECRET | Google desktop client secret |
ENZUI_MAIL_MICROSOFT_CLIENT_ID | Microsoft client ID |
The repository bundles no provider credentials.