mailio_imap_proto (mailio v0.2.0)
Pure IMAP4rev1 protocol codec (no I/O).
Two halves, both side-effect free and exhaustively unit-testable:
- command encoders: build the client command bytes for a tag; - response decoding: read_response/1 frames one complete logical response out of a byte buffer (correctly consuming {n} literals that span physical lines), and parse_response/1 turns those bytes into a structured term.
The connection FSM owns all sockets and timing; this module only knows bytes and terms.
Summary
Functions
The UIDs of the ranges as a list, unless there are more than Max.
Format a sequence/uid set for a command.
Parse framed response bytes into a structured term.
Parse a uid-set ("1,3:5,9") into sorted, merged {Lo, Hi} ranges. Either end of A:B may come first (RFC 3501, section 9). Parts that are not numbers, or are larger than a 32-bit UID, are ignored. Nothing is expanded, so a short set cannot allocate a large list.
Quote a string for an IMAP command (always quoted form).
Frame one complete logical response from the buffer. Returns the response bytes (including embedded literal data, excluding the final CRLF) and the remaining buffer, or more if incomplete. Uses the default limits, see read_response/2.
Like read_response/1 with explicit limits: max_literal (one literal), max_line (one line outside literals) and max_response (a whole logical response). A peer that announces or sends more gets {error, response_too_large} before the data is buffered.
Like read_response/2, resuming a scan. Start with start. When a response is not complete the answer is {more, Resume}; give Resume back with the longer buffer and the work continues where it stopped, instead of from the first byte. A response that arrives in small pieces, however many lines and literals it has, is then framed in linear work.
How many UIDs the ranges stand for.
Types
Functions
-spec examine_qresync(binary(), binary(), non_neg_integer(), non_neg_integer()) -> iodata().
-spec expand_uid_ranges([{integer(), integer()}], non_neg_integer()) -> {ok, [integer()]} | {error, too_many}.
The UIDs of the ranges as a list, unless there are more than Max.
Format a sequence/uid set for a command.
-spec idle_done() -> iodata().
Parse framed response bytes into a structured term.
-spec parse_uid_ranges(binary()) -> [{pos_integer(), pos_integer()}].
Parse a uid-set ("1,3:5,9") into sorted, merged {Lo, Hi} ranges. Either end of A:B may come first (RFC 3501, section 9). Parts that are not numbers, or are larger than a 32-bit UID, are ignored. Nothing is expanded, so a short set cannot allocate a large list.
Quote a string for an IMAP command (always quoted form).
Frame one complete logical response from the buffer. Returns the response bytes (including embedded literal data, excluding the final CRLF) and the remaining buffer, or more if incomplete. Uses the default limits, see read_response/2.
-spec read_response(binary(), map()) -> {ok, binary(), binary()} | more | {error, response_too_large}.
Like read_response/1 with explicit limits: max_literal (one literal), max_line (one line outside literals) and max_response (a whole logical response). A peer that announces or sends more gets {error, response_too_large} before the data is buffered.
-spec read_response(binary(), map(), resume()) -> {ok, binary(), binary()} | {more, resume()} | {error, response_too_large}.
Like read_response/2, resuming a scan. Start with start. When a response is not complete the answer is {more, Resume}; give Resume back with the longer buffer and the work continues where it stopped, instead of from the first byte. A response that arrives in small pieces, however many lines and literals it has, is then framed in linear work.
-spec select_qresync(binary(), binary(), non_neg_integer(), non_neg_integer()) -> iodata().
-spec uid_count([{integer(), integer()}]) -> non_neg_integer().
How many UIDs the ranges stand for.