Discussion:
Puzzled by mailcap for HTML
(too old to reply)
Peter Pearson
2017-01-29 05:33:29 UTC
Permalink
I've been using this line in my .mailcap, happily, for years:

text/html; w3m -I %{charset} -T text/html %s; nametemplate=%s.html; \
copiousoutput

(It's all one line, but I've broken it here for readability.)

With this line, HTML content gets rendered as plain text (reasonable),
but the status line at the bottom of the window doesn't indicate that
w3m has been invoked. But maybe that's OK. If I "view attachments"
and select an HTML part, there's an indication that w3m has been
invoked, and w3m's output seems to have been piped through a pager.

In an attempt to get more sophisticated w3m functionality, I removed
the "; copiousoutput" at the end of the line. To my surprise, this
results in the message "mailcap entry for type text/html not found"
appearing at the bottom of the window. Yet, if I "view attachments"
and select an HTML part, w3m displays it in a nice, link-clickable
way; so obviously the text/html mailcap entry *has* been found.

Can anybody explain why mutt (a) stops finding the mailcap entry
when I remove the copiousoutput from the end, and (b) uses the
mailcap entry after reporting that it couldn't find it? I'm
quite baffled.

Thanks.

$ mutt -version
Mutt 1.5.21 (2010-09-15)
--
To email me, substitute nowhere->runbox, invalid->com.
Jorgen Grahn
2017-01-29 08:32:49 UTC
Permalink
Post by Peter Pearson
text/html; w3m
-I %{charset}
-T text/html %s;
nametemplate=%s.html;
copiousoutput
(It's all one line, but I've broken it here for readability.)
This doesn't help you, but thanks! I was just promising a friend to
look into my UTF-8 problems when replying to HTML mail, and the
-I %{charset} argument was exactly what I needed! My .mailcap entry
(which I've otherwise cargo-culted in 2013, according to revision
control) now looks like:

text/html; /usr/bin/w3m
-I %{charset}
-dump
-T text/html '%s';
copiousoutput;
description=HTML Text;
nametemplate=%s.html

I would never have figured that out for myself.
Post by Peter Pearson
With this line, HTML content gets rendered as plain text (reasonable),
but the status line at the bottom of the window doesn't indicate that
w3m has been invoked. But maybe that's OK. If I "view attachments"
and select an HTML part, there's an indication that w3m has been
invoked, and w3m's output seems to have been piped through a pager.
In an attempt to get more sophisticated w3m functionality, I removed
the "; copiousoutput" at the end of the line. To my surprise, this
results in the message "mailcap entry for type text/html not found"
appearing at the bottom of the window. Yet, if I "view attachments"
and select an HTML part, w3m displays it in a nice, link-clickable
way; so obviously the text/html mailcap entry *has* been found.
Can anybody explain why mutt (a) stops finding the mailcap entry
when I remove the copiousoutput from the end, and (b) uses the
mailcap entry after reporting that it couldn't find it? I'm
quite baffled.
Sorry, no. mailcap(5) has always been a bit of a mystery to me,
beyond the simplest "this MIME type, this application" relationships.

I found this in the mutt sources though:

if (opt == M_AUTOVIEW)
{
if (!copiousoutput)
found = FALSE;
}

/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
Peter Pearson
2017-01-29 17:10:24 UTC
Permalink
On 29 Jan 2017 08:32:49 GMT, Jorgen Grahn <grahn+***@snipabacken.se> wrote:
[snip]
Post by Jorgen Grahn
if (opt == M_AUTOVIEW)
{
if (!copiousoutput)
found = FALSE;
}
That explains a lot. Thanks.
--
To email me, substitute nowhere->runbox, invalid->com.
Jorgen Grahn
2017-01-29 17:43:06 UTC
Permalink
Post by Peter Pearson
[snip]
Post by Jorgen Grahn
if (opt == M_AUTOVIEW)
{
if (!copiousoutput)
found = FALSE;
}
That explains a lot. Thanks.
You're welcome -- although perhaps you need Roger Bell_West's posting
to explain the reason for the code.

/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
Roger Bell_West
2017-01-29 11:03:31 UTC
Permalink
Post by Peter Pearson
Can anybody explain why mutt (a) stops finding the mailcap entry
when I remove the copiousoutput from the end, and (b) uses the
mailcap entry after reporting that it couldn't find it? I'm
quite baffled.
For in-line display, mutt requires a mailcap entry with copiousoutput
set, because it's going to be using its own pager and not allowing
Post by Peter Pearson
This flag should be given whenever the interpreter is capable of
producing more than a few lines of output on stdout, and does no
interaction with the user. If the mailcap entry speci‐ fies
copiousoutput, and pagination has been requested via the "-p"
command, then the output of the command being executed will be piped
through a pagination program ("more" by default, but this can be
overridden with the METAMAIL_PAGER environment variable).
For interactive display ("view-attachment") it's acceptable to
interact with the user directly, so the flag isn't required.
Peter Pearson
2017-01-29 18:15:28 UTC
Permalink
Post by Roger Bell_West
Post by Peter Pearson
Can anybody explain why mutt (a) stops finding the mailcap entry
when I remove the copiousoutput from the end, and (b) uses the
mailcap entry after reporting that it couldn't find it? I'm
quite baffled.
For in-line display, mutt requires a mailcap entry with copiousoutput
set, because it's going to be using its own pager and not allowing
Post by Peter Pearson
This flag should be given whenever the interpreter is capable of
producing more than a few lines of output on stdout, and does no
interaction with the user. If the mailcap entry speci‐ fies
copiousoutput, and pagination has been requested via the "-p"
command, then the output of the command being executed will be piped
through a pagination program ("more" by default, but this can be
overridden with the METAMAIL_PAGER environment variable).
For interactive display ("view-attachment") it's acceptable to
interact with the user directly, so the flag isn't required.
Thanks. In conjunction with the very convincing code snippet that
Jorgen Grahn shared, this paints a clear picture.

What I *think* I want to do (subject to experimental confirmation that
w3m doesn't leak information by requesting img files or the like) is to
have mutt routinely use interactive w3m to display HTML content. If you
happen to know the secret, I wouldn't mind a hint.

Thanks.
--
To email me, substitute nowhere->runbox, invalid->com.
Michael Tatge
2017-01-29 18:19:13 UTC
Permalink
Post by Peter Pearson
text/html; w3m -I %{charset} -T text/html %s; nametemplate=%s.html; \
copiousoutput
With this line, HTML content gets rendered as plain text (reasonable),
but the status line at the bottom of the window doesn't indicate that
w3m has been invoked. But maybe that's OK. If I "view attachments"
and select an HTML part, there's an indication that w3m has been
invoked, and w3m's output seems to have been piped through a pager.
In an attempt to get more sophisticated w3m functionality, I removed
the "; copiousoutput" at the end of the line.
Can anybody explain why mutt (a) stops finding the mailcap entry
when I remove the copiousoutput from the end, and (b) uses the
mailcap entry after reporting that it couldn't find it? I'm
quite baffled.
Maybe https://dev.mutt.org/trac/wiki/MuttFaq/Attachment explains a little more.

Michael
--
PGP-Key-ID: EEE7D043
Jabber: ***@jabber.de
Peter Pearson
2017-01-30 06:00:43 UTC
Permalink
Post by Michael Tatge
Post by Peter Pearson
text/html; w3m -I %{charset} -T text/html %s; nametemplate=%s.html; \
copiousoutput
With this line, HTML content gets rendered as plain text (reasonable),
but the status line at the bottom of the window doesn't indicate that
w3m has been invoked. But maybe that's OK. If I "view attachments"
and select an HTML part, there's an indication that w3m has been
invoked, and w3m's output seems to have been piped through a pager.
In an attempt to get more sophisticated w3m functionality, I removed
the "; copiousoutput" at the end of the line.
Can anybody explain why mutt (a) stops finding the mailcap entry
when I remove the copiousoutput from the end, and (b) uses the
mailcap entry after reporting that it couldn't find it? I'm
quite baffled.
Maybe https://dev.mutt.org/trac/wiki/MuttFaq/Attachment explains a little more.
Many thanks. That page led to Gary Johnson's Mutt Page,

http://www.spocom.com/users/gjohnson/mutt/

which led to my trying the following .mailcap file:

# From Gary Johnson's Mutt Page.
# "copiousoutput" means that the viewer being invoked produces output
# suitable for a pager. An entry without copiousoutput will not be
# considered for something being displayed by mutt's top-level pager,
# but will be considered when viewing attachments.
text/html; w3m %s; nametemplate=%s.html
text/html; w3m -dump %s; nametemplate=%s.html; copiousoutput

This seems satisfactory. (I depart from Gary Johnson's suggestion,
which begins with an entry passing the HTML part to Firefox, because
there are too many ways bad guys can use Firefox -- or any full-function
browser -- to work mischief. Example: detecting the moment at which
you viewed the message, by embedding a uniquely named 1-pixel-by-1-pixel
image.)

Thanks again for your help.
--
To email me, substitute nowhere->runbox, invalid->com.
Loading...