Jmap.Client (JMAP v0.0.1)
View SourceJMAP client implementation that handles the core protocol communication.
Summary
Functions
Archives the specified email by moving it to the Archive folder.
Fetches the content of a blob by its ID.
Fetches the full content of a specific email.
Fetches emails from the Inbox.
Fetches a thread by its ID.
Creates a new JMAP client using configuration values.
Creates a new JMAP client with the given configuration.
Functions
Archives the specified email by moving it to the Archive folder.
Fetches the content of a blob by its ID.
Parameters
- client: The JMAP client struct
- blob_id: The ID of the blob to fetch
- type: The expected content type (optional)
- "text/html" or "text/plain" will return a string
- "application/octet-stream" or other types will return binary
Returns
{:ok, content}- on success- For text types: {:ok, string}
- For binary types: {:ok, binary}
{:error, reason}- on failure
Examples
iex> Jmap.Client.fetch_blob(client, "blob123", "text/html")
{:ok, "<html>...</html>"}
iex> Jmap.Client.fetch_blob(client, "blob123", "application/octet-stream")
{:ok, <<...>>}
Fetches the full content of a specific email.
Parameters
- client: The JMAP client struct
- email_id: The ID of the email to fetch
Returns
{:ok, email}- on success{:error, reason}- on failure
Examples
iex> Jmap.Client.fetch_email(client, "email123")
{:ok, %{"subject" => "Hello", "textBody" => "Content..."}}
Fetches emails from the Inbox.
Options
- limit: Maximum number of emails to fetch (default: 50)
- offset: Number of emails to skip (default: 0)
- sort: Custom sort order (default: [%{"isAscending" => true, "property" => "receivedAt"}])
Returns
{:ok, result}- on success, where result contains:- "ids": List of email IDs
- "total": Total number of emails
- "position": Current position in the result set
{:error, reason}- on failure
Fetches a thread by its ID.
Parameters
- client: The JMAP client struct
- thread_id: The ID of the thread to fetch
Returns
{:ok, thread}- on success, containing thread ID and associated email IDs{:error, reason}- on failure
Examples
iex> Jmap.Client.fetch_thread(client, "thread123")
{:ok, %Jmap.Thread{id: "thread123", emailIds: ["email1", "email2"]}}
Creates a new JMAP client using configuration values.
Returns
{:ok, client}- on success{:error, reason}- on failure
Examples
iex> Jmap.new()
{:ok, %Jmap.Client{}}
Creates a new JMAP client with the given configuration.
Parameters
- api_token: The JMAP API token (for Fastmail, generate this in Settings -> Password & Security -> App Passwords)
- provider: The JMAP provider (e.g., :fastmail)
- options: Additional options (optional)
- api_url: Custom API URL (defaults to provider's default)
- timeout: Request timeout in milliseconds (default: 30_000)
Returns
{:ok, client}- on success{:error, reason}- on failure
Examples
iex> Jmap.new("your-api-token", :fastmail)
{:ok, %Jmap.Client{}}