mailio_rfc5322 (mailio v0.2.0)
RFC 5322 / 2045 header parsing (pure, total).
Splits a message into headers and body, unfolds header field bodies, and parses the structured headers Mailio needs: addresses, dates, Message-ID and reference lists, and MIME content headers (with RFC 2231 parameter handling). Unstructured values (Subject, display names) are RFC 2047 decoded via mailio_mime_decode.
Every function is total: malformed input yields a best-effort result, never an exception.
Summary
Functions
Decode an unstructured header value (RFC 2047 + collapse folding WSP).
Parse just the header list from raw bytes (body discarded).
Parse an address-list header (From/To/Cc/...). Group syntax is flattened to its member addresses.
Parse Content-Disposition into {Disposition, Params}.
Parse Content-Type into {Type, SubType, Params}, lowercased type/subtype. Defaults to text/plain when absent or unparseable.
Parse a Date header to Unix epoch seconds (UTC). Returns error if no date can be recovered.
First msg-id token (e.g. of a Message-ID header), without angles.
All msg-id tokens (References / In-Reply-To), angles stripped.
Parse a bare parameter list (no leading value).
Split raw message bytes into {Headers, Body}. Headers are returned as an ordered list of {LowercaseName, UnfoldedValue}; the body is the bytes after the first empty line (separator removed).
Types
Functions
-spec all_headers(binary(), header_list()) -> [binary()].
Decode an unstructured header value (RFC 2047 + collapse folding WSP).
-spec header(binary(), header_list()) -> binary() | undefined.
-spec header(binary(), header_list(), Default) -> binary() | Default.
-spec headers(binary()) -> header_list().
Parse just the header list from raw bytes (body discarded).
Parse an address-list header (From/To/Cc/...). Group syntax is flattened to its member addresses.
Parse Content-Disposition into {Disposition, Params}.
Parse Content-Type into {Type, SubType, Params}, lowercased type/subtype. Defaults to text/plain when absent or unparseable.
Parse a Date header to Unix epoch seconds (UTC). Returns error if no date can be recovered.
First msg-id token (e.g. of a Message-ID header), without angles.
All msg-id tokens (References / In-Reply-To), angles stripped.
Parse a bare parameter list (no leading value).
-spec split(binary()) -> {header_list(), binary()}.
Split raw message bytes into {Headers, Body}. Headers are returned as an ordered list of {LowercaseName, UnfoldedValue}; the body is the bytes after the first empty line (separator removed).