mailio_imap_map (mailio v0.2.0)

IMAP to JMAP mapping (pure).

Translates between IMAP wire concepts and Mailio's JMAP-shaped model: system flags and keywords, folder attributes and names and mailbox roles, and the per-mailbox sync cursor {uidvalidity, highestmodseq, uidnext} and an opaque adapter remote_state binary.

Summary

Functions

Decode an adapter state binary (or initial).

Encode a per-mailbox cursor into an opaque adapter state binary.

Map an IMAP system flag (or keyword) to a JMAP keyword. Unknown server keywords are lowercased; system flags map to their $ form.

Map a JMAP keyword back to an IMAP flag. Returns undefined for keywords that have no IMAP representation (kept local-only).

Stable mailbox id for an IMAP folder. The folder name is the adapter-native id; the sync engine maps it to a local mailbox id.

Determine a mailbox role from SPECIAL-USE attributes, falling back to well-known name heuristics. Returns undefined for ordinary folders.

Functions

decode_state(Bin)

-spec decode_state(binary() | initial) ->
                      #{uidvalidity := non_neg_integer() | undefined,
                        highestmodseq := non_neg_integer() | undefined,
                        uidnext := non_neg_integer() | undefined}.

Decode an adapter state binary (or initial).

encode_state(S)

-spec encode_state(#{uidvalidity := non_neg_integer(),
                     highestmodseq => non_neg_integer() | undefined,
                     uidnext := non_neg_integer(),
                     page => undefined | {added | updated, pos_integer(), non_neg_integer() | undefined}}) ->
                      binary().

Encode a per-mailbox cursor into an opaque adapter state binary.

flag_to_keyword(Kw)

-spec flag_to_keyword(binary()) -> binary().

Map an IMAP system flag (or keyword) to a JMAP keyword. Unknown server keywords are lowercased; system flags map to their $ form.

flags_to_keywords(Flags)

-spec flags_to_keywords([binary()]) -> #{binary() => true}.

is_representable_keyword(Kw)

-spec is_representable_keyword(binary()) -> boolean().

keyword_to_flag(Kw)

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

Map a JMAP keyword back to an IMAP flag. Returns undefined for keywords that have no IMAP representation (kept local-only).

keywords_to_flags(Keywords)

-spec keywords_to_flags([binary()]) -> [binary()].

mailbox_id(ImapName)

-spec mailbox_id(binary()) -> binary().

Stable mailbox id for an IMAP folder. The folder name is the adapter-native id; the sync engine maps it to a local mailbox id.

role_of(Attrs, Name)

-spec role_of([binary()], binary()) -> atom() | undefined.

Determine a mailbox role from SPECIAL-USE attributes, falling back to well-known name heuristics. Returns undefined for ordinary folders.

state_modseq(State)

-spec state_modseq(binary() | initial) -> non_neg_integer() | undefined.

state_uidnext(State)

-spec state_uidnext(binary() | initial) -> non_neg_integer() | undefined.

state_uidvalidity(State)

-spec state_uidvalidity(binary() | initial) -> non_neg_integer() | undefined.