is it possible to have two options for viewing html mail?
Cameron Simpson
cs at cskk.id.au
Sat Oct 24 21:48:46 UTC 2020
On 24Oct2020 20:54, Globe Trotter via Mutt-users <mutt-users at mutt.org> wrote:
>Lots of people send me mail in HTML format (even though I do not like it). I have the following set up in my .mailcap:
>
>text/html; w3m -I %{charset} -T text/html; copiousoutput
>
>so it converts things using w3m more or less okay, however, I am wondering is it possible to have an option for viewing using midori/firefox for the cases where w3m is not enough?
Certainly. You have a few choices (not mutually exclusive).
First up, you could bind a keystroke to feed the current message
to firefox (or whatever browser).
This page on viewing attachments includes a mailcap entry for using
mozilla if the $DISPLAY environment variable is set:
https://gitlab.com/muttmua/mutt/-/wikis/MuttFaq/Attachment
You could easily adapt that test to something more manual/on-demand. It
is written for attachments, so the "%s" in it assumes a filename
(the attachment). So does the mailcap entry for displaying messages.
My mailcap entry reads like this:
text/html; exec 2>&1 && env DISPLAY= unhtml %s; copiousoutput
The primary thing in that line is the display command itself: "unhtml".
That is a personal script which converts the HTML to text. Write your
own, however trivial - start (of course) with the line from your
mailcap.
Importantly, my "unhtml" consults some flags to decide how to do the
render - you could have yours decide to feed the file to firefox instead
of (or as well as) w3m. Here's my code:
https://hg.sr.ht/~cameron-simpson/css/browse/bin/unhtml?rev=tip
It consults some flags to decide what to run - you can see it will use
w3m or lynx depending on my mood. You could use a similar approach to
display via firefox depedning on your mood.
As an example, I have:
set display_filter="mutt-display_filter"
and I use that for rot13 decoding on demand (the on demand being akin to
your "firefox on demand" wish). So the script is here:
https://hg.sr.ht/~cameron-simpson/css/browse/bin-cs/mutt-display_filter?rev=tip
and if the MUTT_ROT13 flag is set, it passes the text through tr do
decode it. Associated with are the following mutt lines:
set my_toggle_rot13="$my_push_wait_key=no<enter><shell-escape>flag ! MUTT_ROT13 -e flag MUTT_ROT13<enter>$my_pop_wait_key"
macro index \Cx "$my_toggle_rot13" 'toggle MUTT_ROT13'
macro pager \Cx "<exit>$my_toggle_rot13<display-message>" 'toggle MUTT_ROT13'
So the ^X keystroke toggles the rot13 mode, which issues a shell command
to toggle my MUTT_ROT13 flag. If I'm displaying a message (the "pager"
macro) it exits the pager, toggles the flag, ad reenters the pager.
That might be a starting point.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Mutt-users
mailing list