Mailroom.IMAP (Mailroom v0.5.2)

View Source

Handles communication with a IMAP server.

Example:

{:ok, client} = Mailroom.IMAP.connect("imap.server", "username", "password")
client
|> Mailroom.IMAP.list
|> Enum.each(fn(mail) ->
  message =
    client
    |> Mailroom.IMAP.retrieve(mail)
    |> Enum.join("\n")
  # … process message
  Mailroom.IMAP.delete(client, mail)
end)
Mailroom.IMAP.reset(client)
Mailroom.IMAP.close(client)

Summary

Functions

add_flags(pid, number_or_range, flags, opts \\ [])

cancel_idle(pid)

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(pid)

connect(server, username, password, options \\ [])

Connect to the IMAP server

The following options are available:

  • ssl - default false, connect via SSL or not
  • port - default 110 (995 if SSL), the port to connect to
  • timeout - default 15_000, the timeout for connection and communication

Examples:

Mailroom.IMAP.connect("imap.server", "me", "secret", ssl: true)
{:ok, pid}

copy(pid, sequence, mailbox_name)

each(pid, items_list \\ [:envelope], func)

email_count(pid)

examine(pid, mailbox_name)

expunge(pid)

fetch(pid, number_or_range, items_list, func \\ nil, opts \\ [])

Fetches the items for the specified message or range of messages

Examples:

> IMAP.fetch(client, 1, [:uid])
#…
> IMAP.fetch(client, 1..3, [:fast, :uid])
#…

idle(pid, opts \\ [])

Options

  • :timeout - (integer) number of milliseconds before terminating the idle command if no update has been received. Defaults to 1_500_00 (25 minutes)

idle(pid, callback_pid, callback_message, opts \\ [])

init(opts)

Callback implementation for GenServer.init/1.

list(pid, reference \\ "", mailbox_name \\ "*")

logout(pid)

mailbox(pid)

recent_count(pid)

remove_flags(pid, number_or_range, flags, opts \\ [])

search(pid, query, items_list \\ nil, func \\ nil)

select(pid, mailbox_name)

set_flags(pid, number_or_range, flags, opts \\ [])

state(pid)

status(pid, mailbox_name, items)

uid_fetch(pid, number_or_range, items_list, opts \\ [])

uid_search(pid, query)

unseen_count(pid)