Module mimemail

A module for decoding/encoding MIME 1.0 email.

Description

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.

Data Types

dkim_options()

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()

dkim_priv_key() = {pem_plain, binary()} | {pem_encrypted, Key::binary(), Passwd::string()}

headers()

headers() = [{binary(), binary()}]

[{<<"Content-Type">>, <<"text/plain">>}]

mime_subtype()

mime_subtype() = binary()

<<"plain">>

mime_type()

mime_type() = binary()

<<"text">>

mimetuple()

mimetuple() = {mime_type(), mime_subtype(), headers(), parameters(), Body::binary() | mimetuple() | [mimetuple()]}

options()

options() = [{encoding, binary()} | {decode_attachment, boolean()} | {dkim, dkim_options()} | {allow_missing_version, boolean()} | {default_mime_version, binary()}]

parameters()

parameters() = #{transfer_encoding => binary(), content_type_params => [{binary(), binary()}], disposition => binary(), disposition_params => [{binary(), binary()}]}

Function Index

decode/1Decode a MIME email from a binary.
decode/2Decode with custom options.
encode/1
encode/2Encode a MIME tuple to a binary.
get_header_value/2Do a case-insensitive header lookup to return the header's value, or undefined.
get_header_value/3Do a case-insensitive header lookup to return that header's value, or the specified default.
parse_headers/1Parse the headers off of a message and return a list of headers and the trailing body.
rfc2047_utf8_encode/1Encode a binary or list according to RFC 2047.

Function Details

decode/1

decode(Email::binary()) -> mimetuple()

Decode a MIME email from a binary.

decode/2

decode(Email::binary(), Options::options()) -> mimetuple()

Decode with custom options

encode/1

encode(MimeMail::mimetuple()) -> binary()

encode/2

encode(X1, Options) -> any()

Encode a MIME tuple to a binary.

get_header_value/2

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/3

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/1

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/1

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