Home > Linux > HTML E-mails And Mutt

HTML E-mails And Mutt

I find myself regularly using terminals and thus have grown to love any tool that allows me to remain in terminal. Mutt is only of those, a fantastic terminal mail client. The only issue is that most people these days send HTML e-mails rather than plain text. This means that when I open them in mutt it is very unreadable. However there is a very simple solution.

First off lets make a simple script to convert the HTML into text. Several terminal based browsers exist and these can do the conversion for us (make sure to place it in your PATH somewhere).

#!/bin/sh

if [ ! -z `which links | grep -v 'no links'` ]
then
  links -html-numbered-links 1 -html-images 1 -dump "file://$@"
elif [ ! -z `which lynx | grep -v 'no lynx'` ]
then
  lynx -force_html -dump "$@"
elif [ ! -z `which w3m | grep -v 'no w3m'` ]
then
  w3m -T text/html -F -dump "$@"
else
  cat $@
fi

Add this to your ~/.muttrc:

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

And then this to your ~/.mailcap:

text/html;html2txt %s; copiousoutput

Start up Mutt and get nothing but text e-mails.

Tags: ,
  1. September 10th, 2009 at 22:09 | #1

    or you could install links2 and put this in your ~/.mailcap

    text/html; links2 %s; nametemplate=%s.html
    text/html; links2 -dump %s; nametemplate=%s.html; copiousoutput

  2. September 11th, 2009 at 22:41 | #2

    @dustybin
    Why not add link2 into the script and therefore expand the ability!

  1. No trackbacks yet.