Jmap.Email (JMAP v0.0.3)

View Source

Represents an email message from the JMAP API.

Summary

Types

Represents an email attachment.

Represents an email address with an optional display name.

Represents the body content of an email, either in text or HTML format.

t()

Represents a complete email message with all its components.

Functions

Creates a new Email struct from raw JMAP data.

Checks if two emails are part of the same thread.

Types

attachment()

@type attachment() :: %Jmap.Email.Attachment{
  blob_id: String.t(),
  charset: String.t() | nil,
  cid: String.t() | nil,
  contents: binary() | nil,
  disposition: String.t() | nil,
  language: String.t() | nil,
  location: String.t() | nil,
  name: String.t() | nil,
  part_id: String.t(),
  size: integer(),
  type: String.t()
}

Represents an email attachment.

Fields:

  • blob_id: Unique identifier for the attachment blob
  • charset: Character encoding if applicable
  • cid: Content-ID for inline attachments
  • disposition: How the attachment should be handled
  • language: Content language code
  • location: URI indicating where the attachment can be found
  • name: Filename of the attachment
  • part_id: Identifier for this specific email part
  • size: Size of the attachment in bytes
  • type: MIME type of the attachment
  • contents: The binary content of the attachment

email_address()

@type email_address() :: %Jmap.Email.EmailAddress{
  email: String.t(),
  name: String.t() | nil
}

Represents an email address with an optional display name.

Fields:

  • name: Optional display name (e.g., "John Doe")
  • email: The actual email address (e.g., "john@example.com")

email_body()

@type email_body() :: %Jmap.Email.EmailBody{
  blob_id: String.t(),
  charset: String.t() | nil,
  cid: String.t() | nil,
  contents: String.t() | nil,
  disposition: String.t() | nil,
  language: String.t() | nil,
  location: String.t() | nil,
  name: String.t() | nil,
  part_id: String.t(),
  size: integer(),
  type: String.t()
}

Represents the body content of an email, either in text or HTML format.

Fields:

  • blob_id: Unique identifier for the content blob
  • charset: Character encoding of the content
  • cid: Content-ID for inline attachments
  • disposition: How the content should be displayed
  • language: Content language code
  • location: URI indicating where the content can be found
  • name: Optional name for the content part
  • part_id: Identifier for this specific email part
  • size: Size of the content in bytes
  • type: MIME type of the content
  • contents: The actual content string

t()

@type t() :: %Jmap.Email{
  attachments: [Jmap.Email.Attachment.t()],
  from: [Jmap.Email.EmailAddress.t()],
  html_body: [Jmap.Email.EmailBody.t()],
  id: String.t(),
  original_quote: Jmap.Email.EmailBody.t() | nil,
  received_at: String.t(),
  subject: String.t(),
  text_body: [Jmap.Email.EmailBody.t()],
  thread_id: String.t(),
  to: [Jmap.Email.EmailAddress.t()]
}

Represents a complete email message with all its components.

Fields:

  • id: Unique identifier for the email
  • subject: Email subject line
  • from: List of sender email addresses
  • to: List of recipient email addresses
  • received_at: Timestamp when the email was received
  • text_body: List of plain text versions of the email body
  • html_body: List of HTML versions of the email body
  • attachments: List of files attached to the email
  • thread_id: Identifier for the conversation thread this email belongs to
  • original_quote: The quoted text from previous emails in the thread

Functions

new(data)

Creates a new Email struct from raw JMAP data.

Parameters

  • data: Map containing the raw email data from JMAP

Examples

iex> data = %{
...>   "id" => "email123",
...>   "subject" => "Hello",
...>   "from" => [%{"email" => "sender@example.com", "name" => "Sender"}],
...>   "to" => [%{"email" => "recipient@example.com", "name" => "Recipient"}],
...>   "receivedAt" => "2024-01-01T00:00:00Z",
...>   "textBody" => [
...>     %{"blobId" => "blob123", "type" => "text/plain"},
...>     %{"blobId" => "blob124", "type" => "text/plain"}
...>   ],
...>   "threadId" => "thread123"
...> }
iex> Email.new(data)
%Email{
  id: "email123",
  subject: "Hello",
  from: [%EmailAddress{email: "sender@example.com", name: "Sender"}],
  to: [%EmailAddress{email: "recipient@example.com", name: "Recipient"}],
  received_at: "2024-01-01T00:00:00Z",
  text_body: [
    %EmailBody{blob_id: "blob123", type: "text/plain"},
    %EmailBody{blob_id: "blob124", type: "text/plain"}
  ],
  html_body: [],
  attachments: [],
  thread_id: "thread123",
  original_quote: nil
}

same_thread?(email1, email2)

Checks if two emails are part of the same thread.

Parameters

  • email1: First Email struct
  • email2: Second Email struct

Examples

iex> email1 = %Email{thread_id: "thread123"}
iex> email2 = %Email{thread_id: "thread123"}
iex> Email.same_thread?(email1, email2)
true

iex> email1 = %Email{thread_id: "thread123"}
iex> email2 = %Email{thread_id: "thread456"}
iex> Email.same_thread?(email1, email2)
false