Letterbox.Address (Letterbox v0.1.0-rc.0)

Copy Markdown View Source

An email address and the name that came with it.

Letterbox.Address.parse_list(~s("Martínez, José" <jose+photos@Example.com>, ana@example.com))
#=> [%Letterbox.Address{name: "Martínez, José", address: "jose+photos@example.com"},
#    %Letterbox.Address{name: nil, address: "ana@example.com"}]

The domain is in lowercase; the local part stays as it came (RFC 5321 lets a server tell Ana from ana, though few do: local/1 and matches?/2 compare it in lowercase). A sub-address, the part after + (jose+photos@), is tag/1.

Lists are read as mail clients write them: names quoted or not, with encoded words (=?utf-8?Q?Jos=C3=A9?=), comments (ana@example.com (Ana), a name when there is no other), groups (Team: a@x, b@x;, undisclosed-recipients:;), and commas inside quotes.

Summary

Functions

The address without its sub-address, in lowercase: photos@in.example.com.

The domain, after the @.

The local part, before the @, in lowercase.

Whether the address is other (an address, as a string or a struct), in lowercase, and with or without a sub-address when other has none.

The first address of a header's value, or nil.

The addresses of a header's value (From, To, Cc, …), in their order.

The sub-address: what follows the first + of the local part (photos+abc123@ gives "abc123"), or nil.

Types

t()

@type t() :: %Letterbox.Address{address: String.t(), name: String.t() | nil}

Functions

base(address)

@spec base(t()) :: String.t()

The address without its sub-address, in lowercase: photos@in.example.com.

domain(address)

@spec domain(t()) :: String.t()

The domain, after the @.

local(address)

@spec local(t()) :: String.t()

The local part, before the @, in lowercase.

matches?(address, other)

@spec matches?(t(), t() | String.t()) :: boolean()

Whether the address is other (an address, as a string or a struct), in lowercase, and with or without a sub-address when other has none.

parse(value)

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

The first address of a header's value, or nil.

parse_list(value)

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

The addresses of a header's value (From, To, Cc, …), in their order.

tag(address)

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

The sub-address: what follows the first + of the local part (photos+abc123@ gives "abc123"), or nil.