Kantoor.Mime (Kantoor v1.0.0)

Turns a raw RFC822 message into what the index stores: an IMAP-style envelope, a body-structure tree (metadata only, attachments never carry content), the header fields, and capped plain search text.

Parsing never raises. If the mail package cannot make sense of a message the result has status: :degraded and is built from a best-effort header scan and the leading bytes of the body. Sizes in the body structure are the sizes of the transfer-DECODED parts (the parser does not expose encoded sizes), so they are approximate for IMAP BODYSTRUCTURE; the exact message size is stored separately.

Summary

Functions

Parses raw. Always returns a result map.

Parses raw into a full Mail.Message tree (bodies transfer-decoded) for rendering. :error when it cannot be parsed. Content is untrusted.

Types

result()

@type result() :: %{
  status: :parsed | :degraded,
  envelope: map(),
  body_structure: map() | nil,
  header_fields: %{optional(String.t()) => [String.t()]},
  search_text: String.t(),
  message_id: String.t() | nil
}

Functions

parse(raw)

@spec parse(binary()) :: result()

Parses raw. Always returns a result map.

parse_tree(raw)

@spec parse_tree(binary()) :: {:ok, Mail.Message.t()} | :error

Parses raw into a full Mail.Message tree (bodies transfer-decoded) for rendering. :error when it cannot be parsed. Content is untrusted.