Skip to main content

Crate mailrs_imap_format

Crate mailrs_imap_format 

Source
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:

  • FLAGSformat_imap_flags / parse_imap_flags map the 6 standard system flags between u32 bitmask and IMAP (\Seen \Flagged …) syntax. Bit assignments are exposed via the FLAG_* pub const so callers can construct masks without round-tripping through strings.
  • INTERNALDATEformat_internal_date(i64) formats a Unix timestamp as IMAP’s "DD-Mon-YYYY HH:MM:SS +ZZZZ".
  • String quotingescape_imap_string / escape_imap_str / quote_or_nil handle IMAP’s "…" quoted-string with \-escapes-or-NIL rules.
  • Address parsingformat_imap_address + format_addr_list turn RFC 5322 addresses (with optional display name) into IMAP’s ((name route mailbox host)) structure.
  • BODY[] section requestsparse_header_fields_request (BODY[HEADER.FIELDS (…)]) + parse_generic_body_sections (BODY[1], BODY[1.MIME], etc.).
  • MIME walkextract_header_section / extract_body_section / extract_header_fields / parse_mime_headers (returns MimeInfo) / split_mime_parts / find_line_offset / trim_part_trailing_newline / extract_mime_part.
  • BODYSTRUCTUREbuild_bodystructure recurses through multipart trees and emits the RFC-9051 §7.5.2 form.

All helpers are pure functions — no I/O, no async.

Structs§

MimeInfo
Parsed Content-Type + Content-Transfer-Encoding + Content-Disposition info extracted from a single MIME part’s header block. Returned by parse_mime_headers.

Constants§

FLAG_ANSWERED
IMAP \Answered system flag. Bit-1.
FLAG_DELETED
IMAP \Deleted system flag (queued for expunge). Bit-3.
FLAG_DRAFT
IMAP \Draft system flag. Bit-4.
FLAG_FLAGGED
IMAP \Flagged system flag (star). Bit-2.
FLAG_RECENT
IMAP \Recent system flag (set by EXAMINE/SELECT). Bit-5.
FLAG_SEEN
IMAP \Seen system 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 — see quote_or_nil for the full quoted-or-NIL decision.
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 INTERNALDATE value ("DD-Mon-YYYY HH:MM:SS +ZZZZ", RFC 9051 §9 ABNF date-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)