How stalwartlabs/mail-server works
Project Type and Purpose
• This is an open-source, all-in-one mail server supporting multiple mail protocols including JMAP, IMAP4/IMAP4rev2, POP3, SMTP, and ManageSieve.
• It incorporates numerous modern features such as spam/phishing filtering, security (TLS, DANE, MTA-STS, DMARC, DKIM, etc.), multi-tenancy, storage backends, and even a web-based administration dashboard.
• The README clearly states that the system is written in Rust and is built to be secure, fast, robust, and scalable.
Breakdown by Major Components (from the file tree and README)
• Multiple Protocol Servers:
• JMAP Server (found under crates/jmap and crates/jmap-proto)
• IMAP Server (crates/imap and crates/imap-proto)
• POP3 Server (crates/pop3)
• SMTP Server (crates/smtp)
• ManageSieve Server (crates/managesieve)
• Common Libraries and Shared Functionality:
• Common utilities, configuration, authentication, logging, and telemetry in crates/common.
• Utilities and helper functions in crates/utils.
• Tokenizers, NLP components in crates/nlp (used for spam filtering and language detection).
• Tracing and event logging functionality in crates/trc.
• Directory and Account Management:
• Crates/directory is responsible for account lookup through various backends (IMAP, LDAP, internal, etc).
• Email Handling:
• Crates/email handles email ingestion, delivery, indexing, and mailbox management.
• Storage Backends:
• Crates/store supports multiple storage backends (RocksDB, FoundationDB, PostgreSQL, MySQL, etc.) along with backends for blob storage, HTTP, and more.
• Spam Filtering:
• Crates/spam-filter provides spam classifier and rule-based filtering.
• Command Line Interface and Administration:
• Crates/cli provides command-line tools to interact with, configure, or maintain the mail server.
• External Resource & Configuration Files:
• Dockerfiles, CI workflows, and configuration in the resources folder indicate Docker/Kubernetes support and operational deployment.
Relationships and Data/Control Flows
• Clients (mail clients, web browsers, etc.) connect to protocol servers:
• For mail retrieval (IMAP/POP3) and sending (SMTP).
• JMAP clients interact with a dedicated JMAP API which also uses WebSocket and Sieve scripting.
• Each protocol server layer communicates with the underlying application logic in the common crate, which aggregates configuration, authentication, and business logic.
• The server components interface with storage backends (through crates/store) for persisting mail data, attachments, and metadata.
• A directory component manages account lookups and authentication (also interfacing with external systems like LDAP/OIDC if needed).
• Spam filtering operates during SMTP inbound (and possibly across protocols) to check messages using the spam-filter crate, integrating with NLP utilities where necessary.
• Management interfaces (likely accessed via a web-based admin console) interact with underlying management modules in directories like crates/main, crates/directory, and parts of crates/smtp (for queue/reporting management).
• Language: Rust (the project is implemented in Rust, using Rust’s package management with Cargo)
• Protocol-specific standards: RFC-driven implementations for JMAP, IMAP, POP3, SMTP, and ManageSieve.
• External protocols: TLS, OAuth2.0, OpenID Connect, ACME for certificate management.
• Observability: OpenTelemetry and Prometheus integrations.
• Storage: Options like RocksDB, PostgreSQL, MySQL, FoundationDB, SQLite, S3, etc.