mailio_imap (mailio v0.2.0)

IMAP protocol adapter.

Implements mailio_adapter on top of mailio_imap_conn, turning the sync engine's normalized calls into IMAP command sequences and interpreting the untagged responses. Capability-gated: QRESYNC / CONDSTORE / MOVE are used when the server advertises them, with a UID-FETCH fallback otherwise.

Summary

Types

conn/0

-type conn() ::
          #{pid := pid(),
            caps := #{atom() => boolean()},
            max_vanished => pos_integer(),
            listing_window => pos_integer(),
            max_untagged => pos_integer(),
            max_line => pos_integer(),
            max_list_commands => pos_integer()}.

Functions

append(_, MailboxId, Raw, Keywords)

-spec append(conn(), binary(), binary(), [binary()]) -> {ok, term() | undefined} | {error, term()}.

capabilities(_)

-spec capabilities(conn()) -> #{atom() => boolean()}.

close(Conn)

-spec close(conn()) -> ok.

connect(Config)

-spec connect(map()) -> {ok, conn()} | {error, mailio_error:error_map()}.

expunge(Conn, MailboxId, Uids)

-spec expunge(conn(), binary(), [term()]) -> ok | {error, term()}.

fetch_changes_since(Conn, MailboxId, State, Opts)

-spec fetch_changes_since(conn(), binary(), mailio_adapter:remote_state(), map()) ->
                             {ok, [mailio_adapter:change()], mailio_adapter:remote_state(), more | done} |
                             {error, term()}.

fetch_message(Conn, MailboxId, Uid, Sink)

-spec fetch_message(conn(), binary(), term(), mailio_adapter:fetch_sink()) ->
                       {ok, #{size := non_neg_integer()}} | {error, term()}.

fetch_message(Conn, MailboxId, Uid, Sink, Opts)

-spec fetch_message(conn(), binary(), term(), mailio_adapter:fetch_sink(), map()) ->
                       {ok, #{size := non_neg_integer()}} | {error, term()}.

Like fetch_message/4. With uidvalidity in Opts the message is only fetched when the mailbox still has that UIDVALIDITY; a UID means nothing under another one (RFC 3501, section 2.3.1.1), so the answer is {error, uidvalidity_changed}.

list_mailboxes(_)

-spec list_mailboxes(conn()) -> {ok, [mailio_adapter:remote_mailbox()]} | {error, term()}.

list_uids(Conn, MailboxId)

-spec list_uids(conn(), binary()) -> {ok, [integer()]} | {error, term()}.

list_uids(Conn, MailboxId, Opts)

-spec list_uids(conn(), binary(), #{max => pos_integer()}) -> {ok, [integer()]} | {error, term()}.

mailbox_info(Conn, MailboxId)

-spec mailbox_info(conn(), binary()) ->
                      {ok, #{exists := non_neg_integer(), uidvalidity := pos_integer() | undefined}} |
                      {error, term()}.

move(Conn, FromMailbox, Uid, ToMailbox)

-spec move(conn(), binary(), term(), binary()) -> {ok, term() | undefined} | {error, term()}.

set_keywords(Conn, MailboxId, Uid, Add, Remove)

-spec set_keywords(conn(), binary(), term(), [binary()], [binary()]) -> ok | {error, term()}.

state_uidvalidity(State)

-spec state_uidvalidity(mailio_adapter:remote_state()) -> term().

unwatch(Conn, Ref)

-spec unwatch(conn(), term()) -> ok.

watch(Conn, MailboxId, NotifyPid)

-spec watch(conn(), binary(), pid()) -> {ok, term()} | {error, not_supported | term()}.