NeoMutt Macro - Opening text/html attachment from the index view - demu.red

NeoMutt

NeoMutt is a fork of mutt which mainlines a vast number of needed patches (while removing the headache of having them), and actually has ongoing development.

What is it?
NeoMutt is a command line mail reader (or MUA). It's a version of Mutt with added features.

Why?
The NeoMutt project is hoping to kick-start development on the Mutt project.
NeoMutt has already attracted about twenty developers and enthusiasts.

What have you achieved, so far?
Lots of old Mutt patches have been brought up-to-date, tidied and documented.
Notably, the Sidebar patch has now been adopted by upstream Mutt.

I've been using neomutt for quite some time, and it is a great improvement over the original mutt.

Too Many Emails [that use html]

Sadly, every day I get five to twenty html only emails that are worth enough of my time that I haven't unsubscribed, and don't delete on sight. Of these emails, it feels like 98% are the kind that have no meaningful content in text only view :/ ...

Text Only HTML

Auto viewing html emails as text is a combination of a couple of settings. You can read up on some of it on neomutt's mimesupport page.

muttrc

auto_view text/html
alternative_order text/enriched text/plain text/html text

mailcap

text/html;      ~/.mutt/view_attachment.sh %s html;     test=test -n "$DISPLAY"
text/html;      w3m %s;     nametemplate=%s.html;       needsterminal
text/html;      w3m -v -F -T text/html -dump %s;        copiousoutput

Where auto_view uses the third mailcap entry due to copiousoutput.

Ugg... Image Based HTML

So as I was saying, too many of these emails are gobbledygook unless viewed with images rendered. This means I am in the habit of pressing a number of keys in neomutt to launch them in a browser.

<enter>         ## Open the email, and see that it is illegible
v               ## Open attachment view
<down><down>    ## Select the text/html attachment
<enter>         ## Open the attachment
<super_L> 3     ## Have i3 jump to qutebrowser's workspace

Sure, the last one isn't neomutt's (and I will still have it regardless), but that is approximately four to five keystrokes to do-one-thing...

Black Friday

This spendsgiving thanksgiving I got at least 100 emails trying to get me to spend money, and I thought about how I wanted a better way to open the html emails from sources I at least wanted to glance at.

...Cyber Monday

And then cyber monday rolled around and I got another 300 emails (I may be exaggerating).

The Macro

Initially I was overthinking the issue, and trying to find some fancy answer. My thanks to the people on freenode's #neomutt for humoring me (flatcap, antonio_). After stepping a bit back from the issue and looking at my other macros, I think I have a fairly succinct answer which should work in most situations:

muttrc

## Make quick html view macro
bind index,pager V  noop        ## Unbinds V from version
macro index,pager V "<view-attachments><search>html<enter><view-mailcap><exit>"

where <view-attachments> opens the attachment view, <search>html<enter> searchs for 'html' and selects the result, and <view-mailcap><exit> opens the text/html attachment with the mailcap and returns to the starting view.

Notes

  • This would need a line like text/html; ~/.mutt/view_attachment.sh %s html; test=test -n "$DISPLAY" in your mailcap.
  • This assumes that there is only one html mime type in the file. I haven't run into more than one.

The Results

I get to press less keys (one, plus a workspace switch) when I read my annoying html emails for of images!

NeoMutt
mutt
mimesupport

- demure