View Source mimemail (gen_smtp v1.2.0)
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.
You should see the relevant RFCs (2045, 2046, 2047, etc.) for more information.
Note that parts of this module (e.g.,decode/2
) use the iconv library for string conversion, which you will need to explicitly list as a dependency.
Link to this section Summary
Functions
undefined
.Link to this section Types
Specs
dkim_options() :: [{h, [binary()]} | {d, binary()} | {s, binary()} | {t, now | calendar:datetime()} | {x, calendar:datetime()} | {c, {simple | relaxed, simple | relaxed}} | {a, 'rsa-sha256' | 'ed25519-sha256'} | {private_key, dkim_priv_key()}].
Specs
dkim_priv_key() :: {pem_plain, binary()} | {pem_encrypted, Key :: binary(), Passwd :: string()}.
Specs
hdr_token() :: binary() | {Encoding :: binary(), Data :: binary()}.
Specs
headers() :: [{binary(), binary()}].
Specs
mime_subtype() :: binary().
[{<<"Content-Type">>, <<"text/plain">>}]
Specs
mime_type() :: binary().
<<"plain">>
Specs
mimetuple() :: {mime_type(), mime_subtype(), headers(), parameters(), Body :: binary() | mimetuple() | [mimetuple()]}.
Specs
options() :: [{encoding, binary()} | {decode_attachment, boolean()} | {dkim, dkim_options()} | {allow_missing_version, boolean()} | {default_mime_version, binary()}].
Specs
parameters() :: #{transfer_encoding => binary(), content_type_params => [{binary(), binary()}], disposition => binary(), disposition_params => [{binary(), binary()}]}.
Link to this section Functions
Specs
decode(Email :: binary()) -> mimetuple().
Specs
Decode with custom optionsSpecs
encode(MimeMail :: mimetuple()) -> binary().
Specs
get_header_value(Needle :: binary(), Headers :: [{binary(), binary()}]) -> binary() | undefined.
undefined
.
Specs
get_header_value(Needle :: binary(), Headers :: [{binary(), binary()}], Default :: any()) -> binary() | any().
Specs
parse_headers(Body :: binary()) -> {[{binary(), binary()}], binary()}.