# multipart/alternative

[RFC1341] defines MIME types, a mechanism for email clients to figure
out what to do with a message type.

One of these special type is "multipart/alternative", which means that the
message body is available under multiple formats, for example text/plain
and text/html.

Multipart messages look as follows:

> Content-Type: multipart/alternative; boundary="Any piece of text, really"
> The blank line above is needed to separate the headers from the body.
> In the case of multipart messages, everything between the headers and
> first boundary is ignored. This text is still sent, however.
> --Any piece of text, really
> Content-Type: text/html; charset="UTF-8"
> <h1>Don't use HTML in emails!</h1>
> <p>Check the text/plain version of this email instead.<p>
> <!-- doing that is a dick move, don't do it! -->
> --Any piece of text, really
> Content-Type: text/plain; charset="UTF-8"
> Good, good…
> --Any piece of text, really--
> Anything after the last boundary (note the trailing "--") is also
> ignored by the client.

The last part of a multipart message is considered the most important,
and is usually displayed by default (unless your client has a preference
order set).

# mutt(1)

As one of the oldest email clients, mutt(1) can _of course_ send
multipart/alternative messages:

	set send_multipart_alternative=yes
	set send_multipart_alternative_filter=/usr/local/bin/to_html.sh

Setting this in your config file, and sending an email will automatically
convert any email you send as multipart/alternative, add the current
message, and append an alternative message by passing the message body
inside the filter defined.

The expected filter output is

> Converted message body

Both empty lines are important. A filter script to convert text/plain
emails to text/html would thus be (assuming markdown input):

	echo text/html

If you don't want all your emails to be sent with an alternative body,
you can put it in a macro:

	send-hook . "set send_multipart_alternative=no"
	set send_multipart_alternative_filter=/usr/local/bin/to_html.sh
	macro compose M ':set send_multipart_alternative=yes<Enter>' "Add HTML alternative"

The `send-hook` is needed to reset the value to its default value after
sending an email. This way you'll only send the HTML alternative when
you specify it explicitely

[RFC1341]: https://tools.ietf.org/html/rfc1341