links2  mutt  tutorial 

2024-03-01

text/html, quoted, utf-8, 68k

Reading html emails in mutt with links2

Sometimes you get an email, which doesn't come with a plain text version, making it hard to read without a web browser. There are easier ways than the following, but they require more/different software. This method parses an email through links2 and displays it.

code

Save the following as an executable. Preferably inside $PATH. I call it mr, placed inside ~/bin.

#!/bin/sh
tmp=/tmp/muttmail.html
cat - > $tmp
[ "$1" = "" ] && (links -dump $tmp | less) || links -g $tmp
:>$tmp

Since links doesn't understand '-' redirection, this firstly cats the email into a temporary file 'muttmail.html'. The html extension ensures links knows to parse the html tags into a readable form (this can also be forced on any file with a -force-html flag).

The test line checks if mr is run with any arguments. If it is not, it dumps the email into less. Typing mr with any argument - ie: mr g opens the email in graphical links, with clickable urls and (depending on your links configuration) loads images. Lastly the temporary file is emptied.

in practice

Select an email. Press v. Select the text/html file and press '|' and type mr, the parsed email opens in less. Or type mr whatever, the email opens in graphical links.