RustPost

Getting started

Architecture

The crates, the single binary and its roles, PostgreSQL and the blob store, the change sequence, and what scales and how.

On this page

RustPost is one Rust program, rustpost, built from a Cargo workspace of small crates. The webmail and the admin console are static single-page apps (React and MUI) that the server serves; Node.js is only used to build them.

One binary

rustpost serve starts everything the configuration file asks for:

RoleDefault portNotes
SMTP25Always on. Inbound mail from other servers.
Submission587, 465Optional. Mail clients send here, with a login, over TLS only.
IMAP143, 993Optional. Logins only over TLS.
ManageSieve4190Optional. STARTTLS on the same port.
HTTPS443Optional. Webmail, admin console, JMAP for the webmail, CalDAV and CardDAV at /dav/, WKD, autoconfiguration.
Queue workernoneOn by default; delivers outbound mail, invitations and rule runs.

Background jobs also run in the same process: deleting old message traces, syncing antispam settings, purging calendar and contact tombstones, indexing the directory, expiring web sessions and uploads.

The other subcommands manage the store without starting the server: domain add, domain dkim, user add, admin grant and admin revoke. See Installation.

The crates

CrateWhat it does
rp-coreShared ids and value types.
rp-storeThe storage interface, with no SQL, and its conformance suite.
rp-store-postgresThe store on PostgreSQL (sqlx) and its migrations.
rp-blobImmutable, content-addressed blobs on the filesystem.
rp-busIn-process wake-up notices.
rp-mailThe single API for changing mail; every protocol goes through it.
rp-mimeWrapper around the mail-parser crate.
rp-mailauthDKIM signing and SPF, DKIM, DMARC and ARC checks (wraps mail-auth).
rp-smtp-wire, rp-smtpSMTP parsing (wraps smtp-proto) and the inbound and submission servers.
rp-queueOutbound delivery, retries, delivery reports, smarthosts.
rp-imap-wire, rp-imapIMAP parsing (wraps imap-codec) and the IMAP server.
rp-sieveA Sieve parser, checker and interpreter of its own.
rp-managesieveManageSieve (RFC 5804).
rp-identityLocal passwords (Argon2) and SASL.
rp-antispamScreening of mail on port 25.
rp-httpStatic files, sessions, CSRF, JMAP transport, DAV, WKD, autoconfiguration.
rp-jmapThe JMAP subset the webmail speaks.
rp-admin-apiThe REST API of the admin console.
rp-dav, rp-calendar, rp-icalCalDAV and CardDAV, calendars, iCalendar.
rp-contacts, rp-vcardContacts, the directory, vCard.
rp-cryptoOpenPGP and S/MIME public keys, WKD, key lookups.
rp-netTCP with TLS (rustls with the aws-lc-rs provider).
rustpostThe binary: configuration and command line.

Third-party protocol libraries stay behind the wrapper crates, and cargo deny enforces it. That keeps the dependency on any one library replaceable.

Storage

PostgreSQL holds everything except message bodies: accounts, mailboxes, message metadata, flags, the queue, calendars, contacts, Sieve scripts, public keys, sessions, message traces and settings saved from the console. It is the only database. Migrations run when the server starts, under a database-wide lock, so nodes that start together migrate one at a time.

The blob store holds message bodies and attachments as files under [blobs] path, at <org>/<aa>/<bb>/<sha256>. A blob is written to a temporary file, flushed with fsync, renamed into place, and its directories are flushed too. Only then is the metadata committed, and only then does SMTP answer 250.

Blobs are immutable and never contain local paths in the database, so the store can move to S3 later under the same addresses. S3 support is planned.

The change sequence

Every account has one counter. Each transaction that changes the account first reserves a range of that counter by updating the account row, which also locks it, so the commit order and the sequence order are the same. The sequence feeds IMAP MODSEQ values and the webmail's JMAP state, and a change log records what changed at each step. Calendars, contacts and keys use the same counter.

That is why IMAP and the webmail always agree: they read the same history.

What scales and how

The design rule is that durable state lives only in PostgreSQL and the blob store, never in a node's memory. Today:

  • Shared between nodes already: web sessions, the outbound queue (recipients are leased, 15 minutes by default), periodic jobs that must run once (a job_lease row picks one node), and the per-row inboxes for invitations, Autocrypt and rule runs.
  • Per node: rate limits (counted in memory), the admin console's log view, and the wake-up bus. IMAP IDLE also polls every 30 seconds, so a change made on another node shows up within that time.
  • Planned: S3 blobs, a cross-node bus, PROXY protocol, and a tested two-node setup.

The plan's stages, all design targets that have not been measured:

StageBackendsTarget
S0PostgreSQL and filesystem blobs, one nodeabout 2,000 mailboxes
S1PostgreSQL and S3, one active nodeabout 10,000 mailboxes
S23 to 6 stateless nodes10,000 to 50,000 mailboxes

Security model in one paragraph

TLS 1.2 and 1.3 everywhere passwords travel; logins are refused on plain connections. The webmail uses a __Host- session cookie and a CSRF header check, renders mail in a sandbox with remote content blocked, and does all end-to-end cryptography in the browser. The code forbids unsafe. See Security.