Letterbox.MIME.Header (Letterbox v0.1.0-rc.0)

Copy Markdown View Source

The headers of an email or of one of its parts (RFC 5322 and MIME), read as mail clients write them, not only as the RFCs say they should.

  • parse/1 - a block of headers as {name, value} pairs, in their order: names in lowercase, values unfolded and not yet decoded.
  • decode/1 - a value's encoded words (RFC 2047, =?utf-8?Q?Jos=C3=A9?=) in UTF-8, adjacent ones of one charset joined before they are read, so a character split across two words survives; raw 8-bit text (RFC 6532) as UTF-8, else as Windows-1252.
  • params/1 - a structured value (Content-Type, Content-Disposition): its value and its parameters, with RFC 2231's (filename*=utf-8''praia%20%C3%A0%20tarde.jpg, and the parts of a long one, filename*0*, filename*1*) and the encoded words that Outlook and Gmail put in quoted ones.

Summary

Types

t()

A header: its name in lowercase, and its value as it came, unfolded.

Functions

A header's value in UTF-8: its encoded words decoded, and the spaces between two of them taken out, as RFC 2047 says.

The first value of name (lowercase) in headers, or nil.

Every value of name (lowercase) in headers, in their order.

A structured value and its parameters: {"multipart/mixed", %{"boundary" => "…"}}. The value is in lowercase and so are the parameters' names; their values are decoded (RFC 2231, RFC 2047, quoted strings) to UTF-8.

The headers of a block of header lines (CRLF or LF), unfolded. A line that is not a header and does not continue one is left out.

Types

t()

@type t() :: {String.t(), String.t()}

A header: its name in lowercase, and its value as it came, unfolded.

Functions

decode(value)

@spec decode(String.t() | nil) :: String.t() | nil

A header's value in UTF-8: its encoded words decoded, and the spaces between two of them taken out, as RFC 2047 says.

get(headers, name)

@spec get([t()], String.t()) :: String.t() | nil

The first value of name (lowercase) in headers, or nil.

get_all(headers, name)

@spec get_all([t()], String.t()) :: [String.t()]

Every value of name (lowercase) in headers, in their order.

params(value)

@spec params(String.t() | nil) ::
  {String.t() | nil, %{required(String.t()) => String.t()}}

A structured value and its parameters: {"multipart/mixed", %{"boundary" => "…"}}. The value is in lowercase and so are the parameters' names; their values are decoded (RFC 2231, RFC 2047, quoted strings) to UTF-8.

parse(block)

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

The headers of a block of header lines (CRLF or LF), unfolded. A line that is not a header and does not continue one is left out.