Expand description
Maildir filesystem format helpers.
mailrs-maildir implements the Maildir mail storage convention
invented by Daniel J. Bernstein for qmail and adopted by Dovecot,
Courier, mutt, neomutt, postfix, and many others. Messages are stored
as one file per message under <root>/{tmp,new,cur}/, with the
filename encoding a globally unique ID plus a flag suffix.
This crate gives you the primitives — atomic delivery into new/,
directory scans, flag parsing/serialization, and tmp/ cleanup —
without any mailbox-database, indexing, or IMAP/POP3 logic on top.
This crate underpins the message storage in mailrs, a Rust mail server, and is published independently so other Rust projects can reuse the Maildir layer.
§Quick start
use mailrs_maildir::Maildir;
let md = Maildir::create("/var/mail/alice/INBOX").unwrap();
let id = md.deliver(b"From: a@example.com\r\nSubject: hi\r\n\r\nbody\r\n").unwrap();
for entry in md.scan_new().unwrap() {
println!("{} flags={:?}", entry.id, entry.flags);
}§What this crate does
- Atomic delivery:
Maildir::deliverwrites totmp/, fsyncs, then renames intonew/— the standard Maildir reliability technique. - Directory scans:
Maildir::scan_newandMaildir::scan_curlist messages in each stage with their parsed flags. - Filename parsing:
parse_flags/serialize_flags/add_flaghandle the":2,FLAGS"suffix convention. - Janitorial:
Maildir::cleanup_tmpremoves stale partial deliveries.
§What this crate does NOT do
- No IMAP / POP3 protocol layer. See
mailrs-imap-proto. - No mailbox indexing or message search. The
cur/-vs-new/split is the only state — there’s no UID database here. - No locking. Maildir is designed to be lock-free for delivery (atomic rename) and stage transitions (atomic rename).
Structs§
- Entry
- One scanned message entry from
new/orcur/. - Maildir
- A handle to a Maildir directory. Cheap to clone — only holds a path.
- Message
Id - Globally unique identifier of a delivered message, derived from the
filename in
new/orcur/(the part before the:2,FLAGSsuffix).
Enums§
- Flag
- Standard Maildir flag, as defined by the Maildir specification.
Functions§
- add_
flag - Add a flag to an existing
:2,FLAGSinfo string, returning the new info string. No-op ifflagis already present. - parse_
flags - Parse flags from the
":2,FLAGS"suffix of a Maildir filename. Returns a sorted, deduplicatedVec<Flag>. - serialize_
flags - Serialize flags to the
":2,FLAGS"suffix format. Flags are sorted and deduplicated for a canonical representation.