View Source Mail.Parsers.RFC2822 (mail v0.4.3)
RFC2822 Parser
Will attempt to parse a valid RFC2822 message back into
a %Mail.Message{}
data model.
Examples
iex> message = """
...> To: user@example.com\r
...> From: me@example.com\r
...> Subject: Test Email\r
...> Content-Type: text/plain; foo=bar;\r
...> baz=qux;\r
...> \r
...> This is the body!\r
...> It has more than one line\r
...> """
iex> Mail.Parsers.RFC2822.parse(message)
%Mail.Message{body: "This is the body!\r\nIt has more than one line", headers: %{"to" => ["user@example.com"], "from" => "me@example.com", "subject" => "Test Email", "content-type" => ["text/plain", {"foo", "bar"}, {"baz", "qux"}]}}
Summary
Functions
Parses a RFC2822 message back into a %Mail.Message{}
data model.
Retrieves the "name" and "address" parts from an email message recipient (To, CC, etc.). The following is an example of recipient value
Parses a RFC2822 timestamp to a DateTime with timezone
Functions
@spec parse( binary() | nonempty_maybe_improper_list(), keyword() ) :: Mail.Message.t()
Parses a RFC2822 message back into a %Mail.Message{}
data model.
Options
:charset_handler
- A function that takes a charset and binary and returns a binary. Defaults to return the string as is.
Retrieves the "name" and "address" parts from an email message recipient (To, CC, etc.). The following is an example of recipient value:
Full Name <fullname@company.tld>, another@company.tld
In this example, Full Name
is the "name" part and fullname@company.tld
is
the "address" part. another@company.tld
does not have a "name" part, only
an "address" part.
The return value is a mixed list of tuples and strings, which should be interpreted in the following way:
- When the element is just a string, it represents the "address" part only
- When the element is a tuple, the format is
{name, address}
. Both "name" and "address" are strings
@spec to_datetime(binary()) :: DateTime.t() | {:error, binary()}
Parses a RFC2822 timestamp to a DateTime with timezone
RFC2822 3.3 - Date and Time Specification
Also supports obsolete format described in RFC2822 4.3 and invalid timestamps encountered in the wild. The return value will be either a UTC DateTime, or an error tuple returning the invalid date string.