Expand description
IMAP wire-format helpers (RFC 9051 §6.4 FETCH responses, §7.5 BODYSTRUCTURE assembly, §9 ABNF for FLAGS / INTERNALDATE).
Pairs with mailrs-imap-proto
(command parsing + session state machine) and
mailrs-imap-codec
(line / literal framing) to form a complete RFC 9051 receive +
response stack.
22 standalone helpers grouped by concern:
- FLAGS —
format_imap_flags/parse_imap_flagsmap the 6 standard system flags betweenu32bitmask and IMAP(\Seen \Flagged …)syntax. Bit assignments are exposed via theFLAG_*pub constso callers can construct masks without round-tripping through strings. - INTERNALDATE —
format_internal_date(i64)formats a Unix timestamp as IMAP’s"DD-Mon-YYYY HH:MM:SS +ZZZZ". - String quoting —
escape_imap_string/escape_imap_str/quote_or_nilhandle IMAP’s"…"quoted-string with\-escapes-or-NILrules. - Address parsing —
format_imap_address+format_addr_listturn RFC 5322 addresses (with optional display name) into IMAP’s((name route mailbox host))structure. - BODY[] section requests —
parse_header_fields_request(BODY[HEADER.FIELDS (…)]) +parse_generic_body_sections(BODY[1],BODY[1.MIME], etc.). - MIME walk —
extract_header_section/extract_body_section/extract_header_fields/parse_mime_headers(returnsMimeInfo) /split_mime_parts/find_line_offset/trim_part_trailing_newline/extract_mime_part. - BODYSTRUCTURE —
build_bodystructurerecurses through multipart trees and emits the RFC-9051 §7.5.2 form.
All helpers are pure functions — no I/O, no async.
Structs§
- Mime
Info - Parsed
Content-Type+Content-Transfer-Encoding+Content-Dispositioninfo extracted from a single MIME part’s header block. Returned byparse_mime_headers.
Constants§
- FLAG_
ANSWERED - IMAP
\Answeredsystem flag. Bit-1. - FLAG_
DELETED - IMAP
\Deletedsystem flag (queued for expunge). Bit-3. - FLAG_
DRAFT - IMAP
\Draftsystem flag. Bit-4. - FLAG_
FLAGGED - IMAP
\Flaggedsystem flag (star). Bit-2. - FLAG_
RECENT - IMAP
\Recentsystem flag (set by EXAMINE/SELECT). Bit-5. - FLAG_
SEEN - IMAP
\Seensystem flag. Bit-0 of the standard u32 mask.
Functions§
- build_
bodystructure - build BODYSTRUCTURE for a message (handles multipart, with extension data)
- escape_
imap_ str - escape double quotes in IMAP string literals
- escape_
imap_ string - Escape
\and"characters for embedding inside an IMAP"…"quoted string. Does NOT add the surrounding quotes — seequote_or_nilfor the full quoted-or-NILdecision. - extract_
body_ section - extract body section from raw message (after \r\n\r\n)
- extract_
header_ fields - extract only the specified header fields from raw message
- extract_
header_ section - extract header section from raw message (up to \r\n\r\n)
- extract_
mime_ part - extract a specific MIME part by number (e.g. “1”, “2”, “1.1”, “1.MIME”)
- find_
line_ offset - find byte offset of line number in body
- format_
addr_ list - format a comma-separated list of addresses into IMAP address list
- format_
imap_ address - parse an email address “Name user@host” or “user@host” into IMAP address structure returns ((name NIL mailbox host)) or NIL if empty
- format_
imap_ flags - convert bitmask flags to IMAP flag string
- format_
internal_ date - Format a Unix timestamp as an IMAP
INTERNALDATEvalue ("DD-Mon-YYYY HH:MM:SS +ZZZZ", RFC 9051 §9 ABNFdate-time). - parse_
generic_ body_ sections - parse all generic BODY[section] requests like BODY[1], BODY[1.1], BODY[1.MIME], BODY.PEEK[1] returns all section specifiers (e.g. [“1”, “1.1”, “1.MIME”])
- parse_
header_ fields_ request - parse BODY[HEADER.FIELDS (field-list)] or BODY.PEEK[HEADER.FIELDS (field-list)] returns (field_names, raw_section_text)
- parse_
imap_ flags - parse IMAP flag names from a FLAGS string like “(\Seen \Flagged)”
- parse_
mime_ headers - parse content-type and transfer-encoding from header text
- quote_
or_ nil - quote a string for IMAP or return NIL if empty
- split_
mime_ parts - split multipart body by boundary, returning each part as raw bytes (including part headers)
- trim_
part_ trailing_ newline - trim trailing CRLF/LF from part body (boundary transport padding per RFC 2046)