Expand description
IMAP protocol parser and response formatter.
mailrs-imap-proto implements the wire-format pieces of RFC 3501
(IMAP4rev1) — tagged command parsing, sequence-set arithmetic, and
response line formatting. It does no I/O and owns no state; it’s the
protocol layer underneath an IMAP server you write yourself.
This crate underpins the IMAP server in mailrs, a Rust mail server, and is published independently so other Rust projects can reuse the parsing layer.
§Quick start
use mailrs_imap_proto::{parse_command, ImapCommand, format_capability};
// parse a wire-format tagged command line
let parsed = parse_command("a001 CAPABILITY").unwrap();
assert_eq!(parsed.tag, "a001");
assert_eq!(parsed.command, ImapCommand::Capability);
// format the matching response
let resp = format_capability(&["IMAP4rev1", "IDLE", "AUTH=PLAIN"]);
assert_eq!(resp, "* CAPABILITY IMAP4rev1 IDLE AUTH=PLAIN\r\n");§What this crate does
- Parsing:
parse_commandturns a tagged command line into aTaggedCommandcontaining a typedImapCommandenum. Covers LOGIN / SELECT / FETCH / STORE / SEARCH / IDLE / APPEND / UID / etc. - Sequence sets:
parse_sequence_setparses IMAP sequence-set syntax ("1","1:5","5:*","1,3,5:10") into aSequenceSetenum;sequence_set_to_uidsexpands it to a concrete UID vec. - Search:
parse_search_criteriaconverts an IMAP SEARCH key list to typedSearchKeyvalues. - Response formatting:
format_ok/format_no/format_badfor tagged responses;format_capability/format_list/format_fetch/format_flags/format_exists/format_recent/format_bye/format_quota/format_quotarootfor untagged responses.
§What this crate does NOT do
- No I/O. No TCP, no TLS, no async runtime, no connection management.
- No mailbox storage or message indexing.
- No session state machine. Unlike
mailrs-smtp-proto, IMAP’s per-connection state (selected mailbox, capability negotiation, pending IDLE) is owned by the caller — this crate just gives typed commands and formatted replies.
Re-exports§
pub use command::ImapCommand;pub use command::ParseError;pub use command::SearchKey;pub use command::TaggedCommand;pub use command::parse_command;pub use command::parse_search_criteria;pub use sequence::SequenceSet;pub use sequence::parse_sequence_set;pub use sequence::sequence_set_to_uids;pub use response::*;