A module for decoding/encoding MIME 1.0 email.
The encoder and decoder operate on the same data structure, which is as follows:
A 5-tuple with the following elements: {Type, SubType, Headers, Parameters, Body}
.
Type
and SubType
are the MIME type of the email, examples are text/plain
or
multipart/alternative
. The decoder splits these into 2 fields so you can filter by
the main type or by the subtype.
Headers
consists of a list of key/value pairs of binary values eg.
{<<"From">>, <<"Andrew Thompson <andrew@hijacked.us>">>}
. There is no parsing of
the header aside from un-wrapping the lines and splitting the header name from the
header value.
Parameters
is a list of 3 key/value tuples. The 3 keys are <<"content-type-params">>
,
<<"dispisition">>
and <<"disposition-params">>
.
content-type-params
is a key/value list of parameters on the content-type header, this
usually consists of things like charset and the format parameters. disposition
indicates
how the data wants to be displayed, this is usually 'inline'. disposition-params
is a list of
disposition information, eg. the filename this section should be saved as, the modification
date the file should be saved with, etc.
Finally, Body
can be one of several different types, depending on the structure of the email.
For a simple email, the body will usually be a binary consisting of the message body, In the
case of a multipart email, its a list of these 5-tuple MIME structures. The third possibility,
in the case of a message/rfc822 attachment, body can be a single 5-tuple MIME structure.
dkim_options() = [{h, [binary()]} | {d, binary()} | {s, binary()} | {t, now | calendar:datetime()} | {x, calendar:datetime()} | {c, {simple | relaxed, simple | relaxed}} | {private_key, dkim_priv_key()}]
dkim_priv_key() = {pem_plain, binary()} | {pem_encrypted, Key::binary(), Passwd::string()}
headers() = [{binary(), binary()}]
[{<<"Content-Type">>, <<"text/plain">>}]
mime_subtype() = binary()
<<"plain">>
mime_type() = binary()
<<"text">>
mimetuple() = {mime_type(), mime_subtype(), headers(), parameters(), Body::binary() | mimetuple() | [mimetuple()]}
options() = [{encoding, binary()} | {decode_attachment, boolean()} | {dkim, dkim_options()} | {allow_missing_version, boolean()} | {default_mime_version, binary()}]
parameters() = #{transfer_encoding => binary(), content_type_params => [{binary(), binary()}], disposition => binary(), disposition_params => [{binary(), binary()}]}
decode/1 | Decode a MIME email from a binary. |
decode/2 | Decode with custom options. |
encode/1 | |
encode/2 | Encode a MIME tuple to a binary. |
get_header_value/2 | Do a case-insensitive header lookup to return the header's value, or undefined . |
get_header_value/3 | Do a case-insensitive header lookup to return that header's value, or the specified default. |
parse_headers/1 | Parse the headers off of a message and return a list of headers and the trailing body. |
rfc2047_utf8_encode/1 | Encode a binary or list according to RFC 2047. |
decode(Email::binary()) -> mimetuple()
Decode a MIME email from a binary.
decode(Email::binary(), Options::options()) -> mimetuple()
Decode with custom options
encode(MimeMail::mimetuple()) -> binary()
encode(X1, Options) -> any()
Encode a MIME tuple to a binary.
get_header_value(Needle::binary(), Headers::[{binary(), binary()}]) -> binary() | undefined
Do a case-insensitive header lookup to return the header's value, or undefined
.
get_header_value(Needle::binary(), Headers::[{binary(), binary()}], Default::any()) -> binary() | any()
Do a case-insensitive header lookup to return that header's value, or the specified default.
parse_headers(Body::binary()) -> {[{binary(), binary()}], binary()}
Parse the headers off of a message and return a list of headers and the trailing body.
rfc2047_utf8_encode(B) -> any()
Encode a binary or list according to RFC 2047. Input is assumed to be in UTF-8 encoding.
Generated by EDoc