Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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...

share|improve this answer
    
Thanks. I'm aware of these possibilities. I'm looking more for an automated approach. <kbd>v</kbd> and HTML is set to open an external browser (and I'd like it to keep that way). <kbd>Ctrl-E</kbd> does only edit the content type of the whole mail not individual parts. –  qbi Jan 29 '13 at 15:24
1  
@qbi, if you type CTRL-E on the currently selected part, it edits that part's content-type. –  Stephane Chazelas Jan 29 '13 at 15:26
    
@qbi, I've updated the answer with another possible approach. –  Stephane Chazelas Jan 29 '13 at 20:26
    
@qbi, with w3m, you need to add -T text/html –  Stephane Chazelas Jan 30 '13 at 7:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.