25

I recently managed to set up my mailcap so that Mutt can show HTML e-mails in the message window:

# ~/.mailcap
text/html; lynx -dump '%s' | more; nametemplate=%s.html; copiousoutput;

which is automated by:

# ~/.muttrc
auto_view text/html

Although I think Lynx does a decent job on converting the HTML to text, sometimes this doesn't cut it and I would like to be able to open the HTML attachment in my web browser Luakit.

Is there a way to transparently do this? A good workflow for me would look like:

  1. open mail (Lynx converts it)
  2. see that it is too complicated for Lynx
  3. press v
  4. navigate to HTML attachment
  5. press Enter to open the mail in Luakit.
Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
romeovs
  • 1,660
  • 5
  • 21
  • 33
  • This doesn't work for you ? `text/html; luakit %s` besides, auto_view doens't matter in this case, since html are actually attachments – daisy Jul 10 '12 at 09:45

2 Answers2

35

You can do this with mutt's mime support.

In addition, you can use this with Autoview to denote two commands for viewing an attachment, one to be viewed automatically, the other to be viewed interactively from the attachment menu.

Essentially, you include two options in your mailcap file1.

text/html; luakit '%s' &; test=test -n "$DISPLAY"; needsterminal;
text/html; lynx -dump %s; nametemplate=%s.html; copiousoutput;

The first entry tests that X is running, and if it is, it hands the file to luakit. The default, however, is determined by the copiousoutput tag, so it will be rendered in Mutt by lynx.

You will need these options in your .muttrc:

auto_view text/html                                   # view HTML automatically
alternative_order text/plain text/enriched text/html  # save HTML for last

If you want to look at it in your browser, it is just a matter of hitting v to view the attached HTML and then m to send it to mailcap.

For convenience, I bind Enter to that function in muttrc:

bind attach <return>    view-mailcap

1. Note, I don't use lynx or luakit, so these options are indicative only.
Shamelessly reproduced from this blog post: https://jasonwryan.com/blog/2012/05/12/mutt/
Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
jasonwryan
  • 71,734
  • 34
  • 193
  • 226
  • If you want to avoid the `needsterminal` for `luakit` have a look a Gary Johnsons [`mutt-netscape` script.](http://www.spocom.com/users/gjohnson/mutt/#html) – Thor Jul 12 '12 at 22:49
  • 1
    Does it really have to read `text/html; text/html; luakit ...` with the text/html repeated? – Jens Apr 07 '13 at 15:54
  • 1
    Is there a way to do this while disabling the loading of external resources (for privacy reasons)? – a3nm Aug 05 '14 at 20:35
  • @a3nm That all depends on the settings in the browser you hand off to... – jasonwryan Aug 05 '14 at 20:42
  • @jasonwryan Yes... I'm looking for a way to invoke Firefox in a way that would disallow any external lookups. – a3nm Aug 05 '14 at 20:45
  • @a3nm I don't know, but I suspect there are privacy extensions for that. – jasonwryan Aug 05 '14 at 20:48
  • @jasonwryan Yes, but of course this only applies to mail loaded in mutt, not to all the browsing I do, so it isn't that easy to find something satisfactory... – a3nm Aug 05 '14 at 20:59
  • Invoking flirefox from the commandline with a specific special profile is easy - that way you could have a private profile specifically for mail reading. – reedstrm Jun 19 '17 at 14:32
  • latest Wayback Machine snapshot of the [`mutt-netscape` script](https://web.archive.org/web/20170425091539/http://www.spocom.com/users/gjohnson/mutt#html) – jchook Mar 08 '19 at 00:57
  • +1 This answer is the base I use. For mine, I just want to hook up with `firefox`, thus my first line in `~./.mailcap` is `text/html; [ $DISPLAY != "" ] && firefox %s &; needsterminal;`, second line is the same, and no `auto_view` in `muttrc` as I prefer text-based. – haxpor Oct 10 '19 at 03:31
1

Borrowing from the ArchWiki, I have this in muttrc to open HTML in my $BROWSER (Firefox, really) when pressing V in the attachment view:

# pipe-entry pipes the current entry to iconv. iconv converts text from one character encoding to another
# See this for a description of Mutt functions: https://muttmua.gitlab.io/mutt/manual-dev.html#functions
set my_mail=/tmp/mutt/mail.html
macro attach V "<shell-escape>mkdir -p $(dirname $my_mail)<enter><pipe-entry>iconv -c --to-code=UTF8 > $my_mail<enter><shell-escape>$BROWSER $my_mail<enter>" "Open attachment with $BROWSER"
Matthias Braun
  • 7,797
  • 7
  • 45
  • 54