4

I'm using mutt to process my mail. There is one sender which declares the wrong content type. The mail arrives with

Content-Type: multipart/alternative;
  boundary=--…

and has two parts. They are declared as:

Content-Type: text/plain; charset=utf-8

and

Content-Type: text/html; charset=utf-8

However both parts of the mail are same. So the plaintext part is full of HTML tags as well as the HTML part. I've tried to discuss it with the sender, but they use some kind of 'enterprise' software where they cannot change those settings.

So I'd like to change the mail locally and maybe remove the text/plain-part or rewrite text/plain to text/html.

What do you consider the best way and what tools can I use to get a readable mail in my case?

qbi
  • 1,369
  • 1
  • 14
  • 32

1 Answers1

2

In mutt, you can type v, and then select the alternative you want to display. You can also change the content-type of a part with Ctrl-E.

As a more generic approach, you could use mutt's display_filter setting:

set display_filter=/path/to/mutt-filter

With mutt-filter being something like:

#! /usr/bin/awk -f
BEGIN {
  cmd="echo '[automatically converted from html to text]'; w3m -T text/html -dump"
}
{l=tolower($0)}
l ~ /<html|<!doctype html/,l ~ /<\/html>/ {
  print | cmd
  next
}
{close(cmd); print}

Which would cause (in what mutt is going to display, not the raw email) anything between <html> and </html> to go through w3m -T text/html -dump (or elinks -dump or your preferred html to text converter).

As that might convert things that it's not meant to (like when <html> does appear in a genuine text/plain part), you might want to adapt it so that it only operates on emails from those guys that send bogus emails, or some even fancier approach like counting the number of tags and convert when reaching a threshold...

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501