Problem with mutt and mailcap has been resolved
#80 Henry, Sunday, 21 November 2010 5:25 PM (Category: Linux)
(Tags: mutt mailcap)

I use mutt as my mailer. It is a text mode mail reader, for very specific reasons relating to work and tunneling and doing email programming. Earlier this year, mutt changed behaviour. Most of the world sends emails that are HTML. This sucks, I think it's stupid, but that's the way it is so I live with it.

I prefer to get email as text/plain, and most of the best emails I receive are in this format. In the headers of an email, most of the time there is a header that specifies what format the content is. Here are some samples:

Content-Type: text/plain; charset="us-ascii"
Content-Type: multipart/alternative;
Content-Type: multipart/encrypted;
Content-Type: text/html; charset=UTF-8

There are three types of HTML in email.

Sensible mailers send an email out with the contents as multipart/alternative and the first part is text/plain and the second part is text/html, and they leave it up to the mail reader to select the most appropriate part for viewing and for me, I get to see the plain text version. Sadly, some of the plain text versions read like this "If you can see this, your mail reader is not set up to view the glory of the HTML we have sent you, so don't be a dumbass and configure your mail reader so you can see all the images and fonts and crap in this email." No thanks.

Some mailers will send an email out with a single part, and they tell you it's text/html. This is okay.

Then there are the bad emailers that construct an email with one part that is HTML, and omit the Content-Type: header in the email, or specify that the contents are text/plain but are really HTML.

Once upon a time, mutt would recognise that there were parts of an email that were HTML or even Microsoft Word documents or images, and it would handle them the old way. The old way was to look in the mailcap file - $HOME/.mailcap. In here, you could put entries to specify how to handle the non-text emails. I had this mailcap file:

application/msword; antiword %s; nametemplate=%s.doc; copiousoutput
image/*; geeqie %s > /dev/null
text/html; links %s; nametemplate=%s.html

If it was a Microsoft Word document, I could press 'v' and it would be fed to the antiword program and displayed on the screen. This worked really nicely. If it was an image, it would be fed to geeqie, the replacement for GQview. And HTML would be handled by links, the text mode Web browser. I had it all set up and it all worked fine.

Earlier this year, a new version of mutt was released, mutt was upgraded on my systems, and my email experience degraded considerably. I would see the raw HTML, and let me tell you, raw HTML produced by most email programs is fundamentally appalling. It's the dregs. I think the assumption is that as no-one ever looks at the raw HTML (hah!!!) they can shove the world's crappiest HTML into the emails because no-one will ever see it. So I got to see the raw HTML and trying to divine the contents of the email became near impossible. In many cases, I stopped reading email from many people. It just wasn't worth my effort.

I did start searching for a solution to the problem. I rewrote my mailcap file, but it soon became apparent that mutt was no longer using the mailcap entries. I asked questions, I read the mutt manual and change lists and nothing made sense. I eventually asked a question about it on, and got the Tumbleweed Badge for my effort. That was asking a question that got no answers, no comments, no votes and very low views. I got depressed by this.

But finally, someone took pity on me and answered my question by referring me to a note by a mutt developer.

Mutt did change behaviour and started displaying content by itself without using external viewers. Even though it inconvenienced me, I can completely understand it. If you rely on old standard Unix techniques, like using the mailcap file, and users do not know about this, and do not know how to configure it, then you get the blame for things looking crappy. Relying on other people in programming just sucks. It's easier to do it yourself.

However, the mutt developers are very clever. They allowed the old behaviour to still exist. Instead of pressing 'v' to view the contents of the email using built in viewers, you can press 'm' to view the contents of the email through the mailcap system. I have aliased 'v' to do the same as 'm', and now I can read all my emails again.

Sadly, the HTML emails are still the most worthless, and I didn't miss anything by not reading them.