mailio_imap_conn (mailio v0.2.0)

IMAP connection FSM (gen_statem).

Owns one TCP/TLS socket and serializes commands over it. The core primitive is run/3: the caller supplies a builder that, given a freshly allocated tag, returns the command bytes (and optional literal payload to send after a + continuation). The FSM sends the command, accumulates untagged responses, and replies with them plus the matching tagged result. Response interpretation lives in mailio_imap so this module only deals with framing and command/response correlation.

States: connect -> greeting -> auth -> ready; running while a command is in flight; idle while in IDLE; backoff between reconnect attempts.

Summary

Functions

A child specification for a supervisor. A connection started with start_link/1 is linked to the process that started it and goes down with it; an application that keeps a connection for a long time starts it under its own supervisor with this. The connection handles its own reconnects, so it is restarted only when it crashes.

Enter IDLE; unsolicited events are sent to NotifyPid as {imap_idle_event, self(), Event}.

Run a command. Builder(Tag) -> {iodata(), Literal | undefined}.

Functions

auth(_, Old, Data)

auth_failed(Type, Old, Data)

backoff(Type, Old, Data)

callback_mode()

capabilities(Pid)

-spec capabilities(pid()) -> [binary()] | {error, term()}.

child_spec(Config)

-spec child_spec(map()) -> supervisor:child_spec().

A child specification for a supervisor. A connection started with start_link/1 is linked to the process that started it and goes down with it; an application that keeps a connection for a long time starts it under its own supervisor with this. The connection handles its own reconnects, so it is restarted only when it crashes.

A supervisor puts the start arguments in its reports, so they must not hold a secret, nor the arguments of a provider, which may be one (the bundled static provider keeps passwords there). Keep the credential under a name with mailio_credentials:register_ref/2 and give credentials => {ref, Name}: the connection looks it up inside its own worker each time it logs in. A token_fun is accepted too, as the fun shows no secret.

close(Pid)

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

connect(Type, Old, Data)

format_status(Status)

greeting(_, Old, Data)

idle(_, Old, Data)

idle_start(Pid, NotifyPid)

-spec idle_start(pid(), pid()) -> ok | {error, term()}.

Enter IDLE; unsolicited events are sent to NotifyPid as {imap_idle_event, self(), Event}.

idle_stop(Pid)

-spec idle_stop(pid()) -> ok | {error, term()}.

init(Config0)

negotiate(_, Old, Data)

ready(_, Old, Data)

response_too_large(Type, Old, Data)

run(Pid, Builder)

-spec run(pid(), fun((binary()) -> {iodata(), binary() | undefined})) ->
             {ok, [term()], {atom(), term(), binary()}} | {error, term()}.

Run a command. Builder(Tag) -> {iodata(), Literal | undefined}.

run(Pid, Builder, Timeout)

-spec run(pid(), fun((binary()) -> {iodata(), binary() | undefined}), timeout()) ->
             {ok, [term()], {atom(), term(), binary()}} | {error, term()}.

running(_, Old, Data)

start_link(Config)

-spec start_link(map()) -> {ok, pid()} | {error, term()}.

starttls(_, Old, Data)

terminate(Reason, State, Data)

tls_failed(Type, Old, Data)