Skip to main content

Crate mailrs_maildir

Crate mailrs_maildir 

Source
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

§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/ or cur/.
Maildir
A handle to a Maildir directory. Cheap to clone — only holds a path.
MessageId
Globally unique identifier of a delivered message, derived from the filename in new/ or cur/ (the part before the :2,FLAGS suffix).

Enums§

Flag
Standard Maildir flag, as defined by the Maildir specification.

Functions§

add_flag
Add a flag to an existing :2,FLAGS info string, returning the new info string. No-op if flag is already present.
parse_flags
Parse flags from the ":2,FLAGS" suffix of a Maildir filename. Returns a sorted, deduplicated Vec<Flag>.
serialize_flags
Serialize flags to the ":2,FLAGS" suffix format. Flags are sorted and deduplicated for a canonical representation.