Kantoor.Mime.Content (Kantoor v1.0.0)

What the message view needs from a raw message: the plain text body, the HTML body (still UNTRUSTED: it must go through Kantoor.Webmail.HtmlSanitizer), the attachment list and the inline (cid:) images.

Parts are addressed by their position in the MIME tree ("1-0" is the first child of the second top-level part); find_part/2 re-parses and returns the decoded bytes for the download route. Nothing here trusts declared types or names: callers must treat every string as hostile.

Summary

Functions

Every attachment of raw with its decoded bytes (for re-attaching a draft's files).

The decoded part with id part_id: {:ok, %{name:, content_type:, data:}} or :error. Only parts parse/1 lists as attachments are addressable.

Extracts the displayable content of raw. Never raises.

Types

attachment()

@type attachment() :: %{
  id: String.t(),
  name: String.t(),
  size: non_neg_integer(),
  content_type: String.t()
}

t()

@type t() :: %Kantoor.Mime.Content{
  attachments: [attachment()],
  html: String.t() | nil,
  inline: %{required(String.t()) => {String.t(), binary()}},
  seen: non_neg_integer(),
  text: String.t() | nil
}

Functions

attachments_with_data(raw)

@spec attachments_with_data(binary()) :: [
  %{name: String.t(), content_type: String.t(), data: binary()}
]

Every attachment of raw with its decoded bytes (for re-attaching a draft's files).

find_part(raw, part_id)

@spec find_part(binary(), String.t()) :: {:ok, map()} | :error

The decoded part with id part_id: {:ok, %{name:, content_type:, data:}} or :error. Only parts parse/1 lists as attachments are addressable.

parse(raw)

@spec parse(binary()) :: t()

Extracts the displayable content of raw. Never raises.