Discussion:
choices on reading HTML emails
Yubin Ruan
2018-04-10 07:57:53 UTC
Permalink
Hi,

Can anyone share some approaches for reading HTML emails.
Currenlty I use w3m:

text/html; w3m -I %{charset} -T text/html; copiousoutput;

But sometimes I receive some HTML mails which can not be handled that well by
w3m, so I want to open that html attachment in a browser. How can I switch
between?

Yubin
David Woodfall
2018-04-10 08:49:05 UTC
Permalink
On Tuesday 10 April 2018 15:57,
Post by Yubin Ruan
Hi,
Can anyone share some approaches for reading HTML emails.
text/html; w3m -I %{charset} -T text/html; copiousoutput;
But sometimes I receive some HTML mails which can not be handled that well by
w3m, so I want to open that html attachment in a browser. How can I switch
between?
Yubin
What I did was make a shell script to save the mail and open it in
elinks when autoview didn't autoopen it for some reason. You can
easily change elinks to another browser:

#!/bin/sh

TMPFILE="/tmp/mutt-elinks.html"
cat /dev/stdin > "$TMPFILE"
sed -ri "s%^(Date:|From:|To:|Cc:|Subject:|X-Mailer:)(.*)%\1\2\<br\>%g" "$TMPFILE"
elinks -force-html "$TMPFILE"
rm -f "$TMPFILE"

And the macro:

macro pager,index,attach Z "|~/.mutt/elinks<enter>"

The sed line is just to add line breaks to the headers.
Brian Salter-Duke
2018-04-10 08:49:37 UTC
Permalink
Post by Yubin Ruan
Hi,
Can anyone share some approaches for reading HTML emails.
text/html; w3m -I %{charset} -T text/html; copiousoutput;
But sometimes I receive some HTML mails which can not be handled that well by
w3m, so I want to open that html attachment in a browser. How can I switch
between?
Yubin
I use

text/html; /home/brian/bin/see_html %s

where see_html is:-

#!/bin/bash
#
# see_html
# script to give choice of viewer for html attachments
#
# Brian Salter-Duke - This version: 13 May 2007
#----------------------------------------------
#
view2="4"
echo "Menu for possible applications."
echo
echo " 1 Use lynx"
echo " 2 Use w3m"
echo " 3 Use Firefox"
echo " 4 Use Google Chrome"
echo " 0 Exit"
echo
echo
echo -n "Type in the number of the application you want: "
read viewer
if [ -z $viewer ]; then
viewer=$view2
fi
#
case $viewer in
0)
exit
;;
1)
echo "lynx -dump -force_html $1"
lynx -dump -force_html $1 > /tmp/out$$
/usr/bin/less /tmp/out$$
rm /tmp/out$$
;;
2)
echo "w3m -dump $1"
#/usr/bin/w3m -dump $1 > /tmp/out$$
/usr/bin/w3m -dump -T text/html -I %{charseti} $1 | /usr/bin/less
#/usr/bin/less /tmp/out$$
#rm /tmp/out$$
;;
3)
echo "Using Firefox for $1"
mutt_bgrun firefox $1
;;
4)
echo "Using google-chrome for $1"
mutt_bgrun google-chrome -enable-plugins $1
;;
esac

I wrote this a long time ago and I now pretty well always use the default
google option. I always have google open and of course always have a terminal
open for mutt.

I do not recall where I got the germ of this idea nor do I recall anything
about the commented out choices for w3n.

I hope it is of some use to others.

Cheers, Brian.
--
"Microsoft is not the answer. It is the question. The answer is 'No'."
-- Unknown
Brian Salter-Duke (Brian Duke) Email: brian(DOTjames(DOTduke(AT)gmail(DOT)com
Arkadiusz Drabczyk
2018-04-10 10:42:18 UTC
Permalink
Post by Brian Salter-Duke
Post by Yubin Ruan
Hi,
Can anyone share some approaches for reading HTML emails.
text/html; w3m -I %{charset} -T text/html; copiousoutput;
But sometimes I receive some HTML mails which can not be handled that well by
w3m, so I want to open that html attachment in a browser. How can I switch
between?
Yubin
I use
text/html; /home/brian/bin/see_html %s
Notice that you don't have to use full paths in .mailcap. As mutt
passes mailcap commands to sh you can use one of these 2 to make your
.mailcap more portable:

text/html; $HOME/bin/see_html %s
text/html; ~/bin/see_html %s

And if see_html is in your $PATH:

text/html; see_html %s

Personally, I use
https://raw.githubusercontent.com/tampakrap/bin/master/viewhtmlmail.py.
The good thing about it is that it can also display images embedded in
html messages. I have this in my .muttrc:

macro pager <F10> "<pipe-message>~/bin/viewhtmlmail.py\n" "ViewHTML in browser"
--
Arkadiusz Drabczyk <***@drabczyk.org>
Matthias Apitz
2018-04-10 09:51:34 UTC
Permalink
Post by Yubin Ruan
Hi,
Can anyone share some approaches for reading HTML emails.
I do use what you can see in my header line 'X-message-flag:'

matthias
--
Matthias Apitz, ✉ ***@unixarea.de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub
Chris Green
2018-04-10 08:44:22 UTC
Permalink
Post by Yubin Ruan
Can anyone share some approaches for reading HTML emails.
text/html; w3m -I %{charset} -T text/html; copiousoutput;
But sometimes I receive some HTML mails which can not be handled that well by
w3m, so I want to open that html attachment in a browser. How can I switch
between?
I have similar, my .mailcap is:-

text/html; /home/chris/bin/muttfox %s
text/html; lynx -dump %s; copiousoutput; nametemplate=%s.html

So I use lynx to view HTML E-Mail by default and to view in my browser
I hit v[iew-attachment] and then 'm' for view-mailcap to view using my
muttfox script. The muttfox script just calls a local or remote
firefox it's only necessary because I run mutt via ssh remotely
someetimes. For normal use you can just call firefox directly.
--
Chris Green
Omen Wild
2018-04-10 16:10:38 UTC
Permalink
The muttfox script just calls a local or remote firefox it's only
necessary because I run mutt via ssh remotely someetimes. For normal
use you can just call firefox directly.
Can you share this script? I have the same issue, but have been manually
working around it over SSH.
--
If everyone were happy all the time, musicians would be out of a job.
Chris Green
2018-04-10 20:09:24 UTC
Permalink
Post by Omen Wild
The muttfox script just calls a local or remote firefox it's only
necessary because I run mutt via ssh remotely someetimes. For normal
use you can just call firefox directly.
Can you share this script? I have the same issue, but have been manually
working around it over SSH.
Here you go, it depends on having somewhere 'out there' on the cloud
to save the message.

#!/bin/bash
#
#
# muttfox: script called by mutt via mailcap to use firefox to view HTML,
# necessary because /usr/bin/firefox exits before firefox has
# actually loaded the HTML file, especially when it's remote
#
# The temporary file to be viewed by Firefox is copied to a dedicated
# user account called 'share' on isbd.uk (Gandi virtual machine). This
# can take a second or two but means that the same code works when my
# laptop is on the home LAN or away from home.
#
# if there's no DISPLAY variable then Firefox can't run, so skip the whole thing
#
if [ -n "$DISPLAY" ]
then
#
#
# copy the file to isbd.uk, $i is /tmp/mutt/<filename>
#
export RSYNC_RSH="ssh -i /home/chris/.ssh/np_id_rsa"
chmod 644 $1
rsync -a $1 isbd.uk:mutt
#
#
# pass the copy to firefox, runs local or remote firefox according to $DISPLAY
#
/usr/bin/firefox http://isbd.uk/mutt/$(basename $1)
fi
--
Chris Green
Akkana Peck
2018-04-10 16:46:08 UTC
Permalink
Post by Chris Green
Post by Yubin Ruan
Can anyone share some approaches for reading HTML emails.
text/html; w3m -I %{charset} -T text/html; copiousoutput;
But sometimes I receive some HTML mails which can not be handled that well by
w3m, so I want to open that html attachment in a browser. How can I switch
between?
I have similar, my .mailcap is:-
text/html; /home/chris/bin/muttfox %s
text/html; lynx -dump %s; copiousoutput; nametemplate=%s.html
So I use lynx to view HTML E-Mail by default and to view in my browser
I hit v[iew-attachment] and then 'm' for view-mailcap to view using my
muttfox script. The muttfox script just calls a local or remote
firefox it's only necessary because I run mutt via ssh remotely
someetimes. For normal use you can just call firefox directly.
I have several ways of dealing with different types of HTML,
though it starts with a mailcap like Chris':

text/html; mimehelper 5 firefox 'file://%s'; nametemplate=%s.html
text/html; lynx -term=xterm -dump %s; nametemplate=%s.html; copiousoutput

Mutt will automatically show html messages using lynx, but if I want
to see them in firefox, I use 'v' to see the attachment list, arrow
down to the attachment and hit return. mimehelper is a script that
runs a program then sleeps for 5 seconds, otherwise mutt often
removes the temp file before the browser has had a chance to read it.
I wish I could make mutt less aggressive about removing its temp files.

Then there's the case of multipart/alternative messages where the
text part (which I prefer in alternative_order) is broken; I don't
necessarily want to open the HTML message in a browser, I just want
to reverse alternative_order so I can see the HTML part it lynx.
I have a binding for that which I got from
http://www.archivum.info/comp.mail.mutt/2008-08/00002/Re-combined-html-ascii-message-mutt-shows-html-but-not-ascii.html

That still leaves the edge case of HTML mail with attached images.
I don't get those very often, but when I do, mutt can't show the
images. So I wrote a Python script that pulls out the cid:
attachments and saves them, then rewrites the HTML to point to them.
http://shallowsky.com/blog/tech/email/mutt-viewing-html-mail.html

Finally, I have a script that brings up a browser window showing all
the attachments, both HTML and Word docs (converted to HTML), in
different tabs. (I unfortunately have to correspond with a group of
people who insist on communicating by mailing bunches of Word
attachments). So I put that on F5:
macro index <F5> "<pipe-message>~/bin/viewmailattachments\n" "View all attachments in browser"
macro pager <F5> "<pipe-message>~/bin/viewmailattachments\n" "View all attachments in browser"
The script is at
https://github.com/akkana/scripts/blob/master/viewmailattachments

That one doesn't handle embedded images; some day I need to combine
viewmailattachments and viewhtmlmail into one script.

...Akkana
Jude DaShiell
2018-04-10 17:10:30 UTC
Permalink
I wonder, can mutt be used to strip all images and toss them in the
trash and strip all image attachments and toss them in the trash then
make remaining text viewable in mutt? Some of us with this kind of
capability could save lots of disk space.
Date: Tue, 10 Apr 2018 12:46:08
Subject: Re: choices on reading HTML emails
Post by Chris Green
Post by Yubin Ruan
Can anyone share some approaches for reading HTML emails.
text/html; w3m -I %{charset} -T text/html; copiousoutput;
But sometimes I receive some HTML mails which can not be handled that well by
w3m, so I want to open that html attachment in a browser. How can I switch
between?
I have similar, my .mailcap is:-
text/html; /home/chris/bin/muttfox %s
text/html; lynx -dump %s; copiousoutput; nametemplate=%s.html
So I use lynx to view HTML E-Mail by default and to view in my browser
I hit v[iew-attachment] and then 'm' for view-mailcap to view using my
muttfox script. The muttfox script just calls a local or remote
firefox it's only necessary because I run mutt via ssh remotely
someetimes. For normal use you can just call firefox directly.
I have several ways of dealing with different types of HTML,
text/html; mimehelper 5 firefox 'file://%s'; nametemplate=%s.html
text/html; lynx -term=xterm -dump %s; nametemplate=%s.html; copiousoutput
Mutt will automatically show html messages using lynx, but if I want
to see them in firefox, I use 'v' to see the attachment list, arrow
down to the attachment and hit return. mimehelper is a script that
runs a program then sleeps for 5 seconds, otherwise mutt often
removes the temp file before the browser has had a chance to read it.
I wish I could make mutt less aggressive about removing its temp files.
Then there's the case of multipart/alternative messages where the
text part (which I prefer in alternative_order) is broken; I don't
necessarily want to open the HTML message in a browser, I just want
to reverse alternative_order so I can see the HTML part it lynx.
I have a binding for that which I got from
http://www.archivum.info/comp.mail.mutt/2008-08/00002/Re-combined-html-ascii-message-mutt-shows-html-but-not-ascii.html
That still leaves the edge case of HTML mail with attached images.
I don't get those very often, but when I do, mutt can't show the
attachments and saves them, then rewrites the HTML to point to them.
http://shallowsky.com/blog/tech/email/mutt-viewing-html-mail.html
Finally, I have a script that brings up a browser window showing all
the attachments, both HTML and Word docs (converted to HTML), in
different tabs. (I unfortunately have to correspond with a group of
people who insist on communicating by mailing bunches of Word
macro index <F5> "<pipe-message>~/bin/viewmailattachments\n" "View all attachments in browser"
macro pager <F5> "<pipe-message>~/bin/viewmailattachments\n" "View all attachments in browser"
The script is at
https://github.com/akkana/scripts/blob/master/viewmailattachments
That one doesn't handle embedded images; some day I need to combine
viewmailattachments and viewhtmlmail into one script.
...Akkana
--
m***@raf.org
2018-04-10 23:35:33 UTC
Permalink
Post by Jude DaShiell
I wonder, can mutt be used to strip all images and toss them in the
trash and strip all image attachments and toss them in the trash then
make remaining text viewable in mutt? Some of us with this kind of
capability could save lots of disk space.
I had the same thought in a job where people kept sending me
large documents I didn't want. Or at least, I wanted text-only
versions of their content. So I wrote http://raf.org/textmail/
which lets you selectively replace non-text attachments with
text-only versions or just delete attachments. It can
dramatically reduce your mailbox size, either as email arrives
(with procmail) or it can be applied to an existing mbox file. It
can probably be used via mutt as a filter but I've always run it
via procmail.

I also had procmail filters that removed all the email signatures
and legal notices that end up accounting for 95% of most
work-related email conversations but that's something that needs
to be constantly tweaked according to the signatures you
encounter.

Here's the usage message for textmail. I haven't used it in a
while and it depends on lots of external programs to do the
translations. I hope they all still work. :-)

These days, I save the attachments I need and then manually
delete attachments from the message in the view attachments menu.

cheers,
raf

usage: textmail [options]
options:
-h - Print the help message then exit
-m - Print the manpage then exit
-w - Print the manpage in html format then exit
-r - Print the manpage in nroff format then exit
-M - Output in mailbox format (mboxrd)
-T - Output in raw mail format (for smtp)
-W - Don't replace MS Word attachments with text
-E - Don't replace MS Excel attachments with csv
-H - Don't replace HTML attachments with text
-R - Don't replace RTF attachments with text
-P - Don't replace PDF attachments with text
-U - Don't translate winmail.dat attachments
-L - Don't reduce appledouble attachments
-I - Don't delete image attachments
-A - Don't delete audio attachments
-V - Don't delete video attachments
-X - Don't delete MS Windows executable attachments
-B - Don't recode text that was base64-encoded
-S - Don't replace spaces in filenames with underscores
-Z - Do translate signed content (discards signatures)
-O - Delete all application/octet-stream attachments
-! - Delete all application/* attachments
-D hdrs - Delete headers (list of header prefixes and filenames)
-K types - Keep attachments (list of mimetypes and filenames)
-f - On translation error, keep translation, not original
-? - Print paths of helper applications then exit
Jude DaShiell
2018-04-10 13:29:01 UTC
Permalink
Interesting, anything different in the headings of webmail not handled
well by w3m as opposed to messages w3m handles well? If so, maybe
isolating that difference and writing an additional line for the
.mailcap file will help.
Date: Tue, 10 Apr 2018 03:57:53
Subject: choices on reading HTML emails
Hi,
Can anyone share some approaches for reading HTML emails.
text/html; w3m -I %{charset} -T text/html; copiousoutput;
But sometimes I receive some HTML mails which can not be handled that well by
w3m, so I want to open that html attachment in a browser. How can I switch
between?
Yubin
--
Grant Edwards
2018-04-10 17:49:27 UTC
Permalink
Post by Yubin Ruan
Hi,
Can anyone share some approaches for reading HTML emails.
text/html; w3m -I %{charset} -T text/html; copiousoutput;
But sometimes I receive some HTML mails which can not be handled that well by
w3m, so I want to open that html attachment in a browser. How can I switch
between?
I have my mailcap entry set up so that "viewing" an html message uses
w3m but "printing" an html message passes it to chromium:

$ fgrep text/html ~/.mailcap
text/html; w3m -T text/html -dump; copiousoutput; print = chromiumurl %s;

$ cat ~/bin/chromiumurl
#!/bin/bash
URL="$1"
test -f "$URL" && URL="file://$URL"
expr match "$URL" '.*://.*' >/dev/null || URL="http://$URL"
exec chromium "$URL"
--
Grant Edwards grant.b.edwards Yow! Am I elected yet?
at
gmail.com
Grant Edwards
2018-04-10 19:34:34 UTC
Permalink
Post by Yubin Ruan
Can anyone share some approaches for reading HTML emails.
[...]
Post by Yubin Ruan
But sometimes I receive some HTML mails which can not be handled
that well by w3m, so I want to open that html attachment in a
browser. How can I switch between?
I have my mailcap entry set up so that "viewing" an html message uses
w3m but "printing" an html message opens it in chromium:

$ fgrep text/html ~/.mailcap

text/html; w3m -T text/html -dump; copiousoutput; print = chromiumurl %s;

$ cat ~/bin/chromiumurl

#!/bin/bash
URL="$1"
test -f "$URL" && URL="file://$URL"
expr match "$URL" '.*://.*' >/dev/null || URL="http://$URL"
exec chromium "$URL"
--
Grant Edwards grant.b.edwards Yow! Am I elected yet?
at
gmail.com
Jens John
2018-04-13 15:26:14 UTC
Permalink
Post by Grant Edwards
I have my mailcap entry set up so that "viewing" an html message uses
w3m but "printing" an html message opens it in chromium
Many thanks for pointing me to the `print=` configuration option in mailcap!

I used to save the HTML message part manually and then open it in the browser for when the w3m rendering was not good enough, and was looking for a workaround to rebind the open action from the message part browser to call a GUI browser. Repurposing the print functionality is a neat trick.

Regards
Jens.
Grant Edwards
2018-04-13 16:43:41 UTC
Permalink
Post by Jens John
Post by Grant Edwards
I have my mailcap entry set up so that "viewing" an html message uses
w3m but "printing" an html message opens it in chromium
Many thanks for pointing me to the `print=` configuration option in mailcap!
I used to save the HTML message part manually and then open it in
the browser for when the w3m rendering was not good enough, and was
looking for a workaround to rebind the open action from the message
part browser to call a GUI browser. Repurposing the print
functionality is a neat trick.
And if you do want to actually print it, doing that from inside
chromium is probably the best option anyway...
--
Grant Edwards grant.b.edwards Yow! It's a lot of fun
at being alive ... I wonder if
gmail.com my bed is made?!?
leo
2018-05-03 06:46:12 UTC
Permalink
Post by Yubin Ruan
Hi,
Can anyone share some approaches for reading HTML emails.
text/html; w3m -I %{charset} -T text/html; copiousoutput;
But sometimes I receive some HTML mails which can not be handled that
well by w3m, so I want to open that html attachment in a browser. How
can I switch between?
In according to this discussion [1] I use this strategy:
By default I read html email in mutt (with elinks).
When the message can not be handled well by elinks I hit "v", I choose
the html part and I watch it with firefox.

This is the part in my muttrc:

bind attach <return> view-mailcap
alternative_order text/plain text/html
unauto_view *
auto_view text/html

And this the mailcap:

text/html; firefox %s;
text/html; elinks -dump %s; nametemplate=%s.html; copiousoutput

Cheers leo


[1] https://lists.debian.org/debian-user/2016/06/msg00554.html
--
leo
GPG Fingerprint: A512 4B1C D217 BA09 7551 B4B1 47AF B00C EE84 B613
Ian Zimmerman
2018-05-03 17:47:32 UTC
Permalink
In according to this discussion [1] I use this strategy: By default I
read html email in mutt (with elinks). When the message can not be
handled well by elinks I hit "v", I choose the html part and I watch
it with firefox.
bind attach <return> view-mailcap
alternative_order text/plain text/html
unauto_view *
auto_view text/html
text/html; firefox %s;
text/html; elinks -dump %s; nametemplate=%s.html; copiousoutput
How does mutt know to prefer the elinks entry initially?
--
Please don't Cc: me privately on mailing lists and Usenet,
if you also post the followup to the list or newsgroup.
To reply privately _only_ on Usenet and on broken lists
which rewrite From, fetch the TXT record for no-use.mooo.com.
leo
2018-05-03 19:04:35 UTC
Permalink
Post by Ian Zimmerman
In according to this discussion [1] I use this strategy: By default I
read html email in mutt (with elinks). When the message can not be
handled well by elinks I hit "v", I choose the html part and I watch
it with firefox.
bind attach <return> view-mailcap
alternative_order text/plain text/html
unauto_view *
auto_view text/html
text/html; firefox %s;
text/html; elinks -dump %s; nametemplate=%s.html; copiousoutput
How does mutt know to prefer the elinks entry initially?
Hi Ian,
I honestly don't know how it chooses the first browser, but for me it
works;)
Maybe here [1] you can find part of the solution.
I'm sorry for the untechnical answer.

Cheers leo

[1]
http://terminalmage.net/2014/03/16/how-i-read-html-email-with-mutt.html
--
leo
GPG Fingerprint: A512 4B1C D217 BA09 7551 B4B1 47AF B00C EE84 B613
Till Smejkal
2018-05-04 07:11:52 UTC
Permalink
Post by Ian Zimmerman
In according to this discussion [1] I use this strategy: By default I
read html email in mutt (with elinks). When the message can not be
handled well by elinks I hit "v", I choose the html part and I watch
it with firefox.
bind attach <return> view-mailcap
alternative_order text/plain text/html
unauto_view *
auto_view text/html
text/html; firefox %s;
text/html; elinks -dump %s; nametemplate=%s.html; copiousoutput
How does mutt know to prefer the elinks entry initially?
If you have auto_view set for a file type, mutt will use a mailcap entry that has the
copiousoutput option set. And only if you view the mail attachments (v) and then open
the attachment (<Enter>), mutt considers other mailcap entries. See the muttrc man
page for more information ;)

Cheers
Till
mwnx
2018-05-15 20:21:58 UTC
Permalink
Post by Yubin Ruan
Hi,
Can anyone share some approaches for reading HTML emails.
text/html; w3m -I %{charset} -T text/html; copiousoutput;
But sometimes I receive some HTML mails which can not be handled that well by
w3m, so I want to open that html attachment in a browser. How can I switch
between?
Yubin
I find that the best way to handle such mail is to "pipe" it into
thunderbird (no configuration needed). This has two advantages:

- Thunderbird knows how to handle embedded images and the like.

- Safety. Opening an html email with firefox may leak information to
the likes of spammers since firefox will attempt to load external
resources (images) without asking, while thunderbird takes these
issues into consideration.

Here's the binding I use in my muttrc:

macro index,pager,compose ,o "<pipe-message>thunderopen<enter>"

When I need to open an email with thunderbird, I just press `,o`.

And here's the `thunderopen` script, which I place in `~/bin/`:

----
#!/bin/bash
# Open an email file from stdin with thunderbird. Useful with mutt's
# pipe-message command.

set -eu

tmp=
trap 'rm -f "$tmp"' EXIT
tmp=$(mktemp --tmpdir thunderopen-XXXXXXX.eml)

cat > "$tmp"
thunderbird --no-remote --new-instance -file "$tmp"
----

One drawback of this method, to which I haven't yet found a fix, is
that you can only open one page at once or thunderbird will complain
about an existing instance. I'm pretty sure there must be some
option to force a new instance, or, in the worst case, it should be
possible to containerize thunderbird to make it unaware of other
instances.
--
mwnx
GPG: AEC9 554B 07BD F60D 75A3 AF6A 44E8 E4D4 0312 C726
Loading...