Miscellaneous ephemera…

Mutt and HTML email

Following on from my last post about Mutt, I have been tinkering more with the most suckless of mail clients to get it to deal with—of all things—HTML emails. I will preface this post with a remark or two that amounts to a warning about intemperate language, ranting and a generally cranky disposition: repeated contact with email marketers can do that to you…

A further brief digression is warranted here. HTML email is, without doubt, evidence of the imminent end of civilized life as we know it; much like the Golgafrincham diaspora, it is attributable to a depraved cabal of marketing consultants and provides the same level of social good as syphilis and fistulas. Suffice to say, it is a blight.

Sadly, it is a blight that I have to deal with. Up until now, I had done that by using the excellent w3m to render HTML as text in Mutt itself. That is accomplished easily enough with an entry in muttrc and another in a mailcap file.

auto_view text/html                                      # view html automatically
alternative_order text/plain text/enriched text/html     # save html for last
text/html; w3m -I %{charset} -T text/html; copiousoutput;

This works for 80 percent of the HTML email I get. It is enough to confirm that the mail is useless and can be discarded. The other 20 percent, however, is slightly more problematic. The initial view in w3m is enough to tell me that, due to the outstanding incompetence of the idiots that generated the email, there is actually some information that is contained in the email that I need to access but it is not viewable in a text browser.

For this special level of retardation, I need to be able to open the email in a graphical browser. As I use vimprobable, that means sending the file to vimprobable running in tabbed. Fortunately, as you would expect with superior software, mutt has a way of handling this gracefully. In Mutt’s extensive documentation, there is a page on Mutt’s MIME support that details how to set up a graduated response to this pernicious issue:

In addition, you can use this with Autoview to denote two commands for viewing
an attachment, one to be viewed automatically, the other to be viewed
interactively from the attachment menu.

So, you can have mutt render the HTML abomination in w3m in most cases, and when those instances of particularly cretinous behaviour make it to your inbox, you can choose to view them in your web browser. In my case, by altering the mailcap entry to look like this:

text/html; vimprobtab.sh %s &; test=test -n "$DISPLAY"; needsterminal;
text/html; w3m -I %{charset} -T text/html; copiousoutput;

The first entry tests that X is running, and if it is, it hands the file to vimprobable. The default, however, is determined by the copiousoutput tag. So, in mutt it is just a matter of hitting v to view the attached HTML and then m to send it to mailcap. For convenience, I bind Enter to that function in muttrc:

bind attach <return>    view-mailcap