mailio_adapter behaviour (mailio v0.2.0)
Protocol adapter behaviour.
Normalizes IMAP (now), JMAP and POP3 (later) into one callback contract the sync engine drives. All ids on this boundary are protocol-native opaque terms; the mapping to immutable JMAP email ids happens in the sync engine, which persists the IMAP uid to emailId map.
The key idea is that adapters are dumb: they translate protocol to these calls and report changes since an opaque cursor. All cursoring, dedup, and conflict logic lives in the sync engine, so a new adapter only has to implement these callbacks.
Summary
Types
-type change() :: {added, #{uid := term(), keywords := [binary()], internal_date => integer(), size => non_neg_integer(), uidvalidity => non_neg_integer()}} | {updated, #{uid := term(), keywords := [binary()]}} | {removed, term()} | reset | resync.
-type conn() :: term().
-type fetch_sink() :: fun((iodata()) -> ok).
-type remote_state() :: binary() | initial.
Callbacks
-callback close(conn()) -> ok.
-callback connect(AccountCfg :: map()) -> {ok, conn()} | {error, mailio_error:error_map()}.
-callback expunge(conn(), MailboxId :: binary(), Uids :: [term()]) -> ok | {error, mailio_error:error_map()}.
-callback fetch_changes_since(conn(), MailboxId :: binary(), remote_state(), Opts :: map()) -> {ok, [change()], remote_state(), more | done} | {error, mailio_error:error_map()}.
-callback fetch_message(conn(), MailboxId :: binary(), Uid :: term(), fetch_sink()) -> {ok, #{size := non_neg_integer()}} | {error, mailio_error:error_map()}.
-callback fetch_message(conn(), MailboxId :: binary(), Uid :: term(), fetch_sink(), Opts :: map()) -> {ok, #{size := non_neg_integer()}} | {error, mailio_error:error_map()}.
-callback list_mailboxes(conn()) -> {ok, [remote_mailbox()]} | {error, mailio_error:error_map()}.
-callback list_uids(conn(), MailboxId :: binary()) -> {ok, [term()]} | {error, mailio_error:error_map()}.
-callback list_uids(conn(), MailboxId :: binary(), #{max => pos_integer()}) -> {ok, [term()]} | {error, mailio_error:error_map()}.
-callback mailbox_info(conn(), MailboxId :: binary()) -> {ok, #{exists := non_neg_integer(), uidvalidity := term()}} | {error, mailio_error:error_map()}.
-callback state_uidvalidity(remote_state()) -> term().
-callback watch(conn(), MailboxId :: binary(), Notify :: pid()) -> {ok, WatchRef :: term()} | {error, not_supported | mailio_error:error_map()}.