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

address/0

-type address() :: #{name := binary() | undefined, email := binary()}.

header_list/0

-type header_list() :: [{binary(), binary()}].

Functions

all_headers(Name, Headers)

-spec all_headers(binary(), header_list()) -> [binary()].

decode_unstructured(Value)

-spec decode_unstructured(binary() | undefined) -> binary() | undefined.

Decode an unstructured header value (RFC 2047 + collapse folding WSP).

header(Name, Headers)

-spec header(binary(), header_list()) -> binary() | undefined.

header(Name, Headers, Default)

-spec header(binary(), header_list(), Default) -> binary() | Default.

headers(Raw)

-spec headers(binary()) -> header_list().

Parse just the header list from raw bytes (body discarded).

parse_addresses(Value)

-spec parse_addresses(binary() | undefined) -> [address()].

Parse an address-list header (From/To/Cc/...). Group syntax is flattened to its member addresses.

parse_content_disposition(Value)

-spec parse_content_disposition(binary() | undefined) -> {binary() | undefined, map()}.

Parse Content-Disposition into {Disposition, Params}.

parse_content_type(Value)

-spec parse_content_type(binary() | undefined) -> {binary(), binary(), map()}.

Parse Content-Type into {Type, SubType, Params}, lowercased type/subtype. Defaults to text/plain when absent or unparseable.

parse_date(Value)

-spec parse_date(binary() | undefined) -> {ok, integer()} | error.

Parse a Date header to Unix epoch seconds (UTC). Returns error if no date can be recovered.

parse_message_id(Value)

-spec parse_message_id(binary() | undefined) -> binary() | undefined.

First msg-id token (e.g. of a Message-ID header), without angles.

parse_message_ids(Value)

-spec parse_message_ids(binary() | undefined) -> [binary()].

All msg-id tokens (References / In-Reply-To), angles stripped.

parse_params(Bin)

-spec parse_params(binary()) -> map().

Parse a bare parameter list (no leading value).

split(Raw)

-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).