View Source Mail.Parsers.RFC2822 (mail v0.4.0)
RFC2822 Parser
Will attempt to parse a valid RFC2822 message back into
a %Mail.Message{}
data model.
Mail.Parsers.RFC2822.parse(message)
%Mail.Message{body: "Some message", headers: %{to: ["user@example.com"], from: "other@example.com", subject: "Read this!"}}
Summary
Functions
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()) :: Mail.Message.t()
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.