Subject: bug#36771: 27.0.50; mailcap documentation and effect missmatch

From: Stefan Kangas <[email-masked]>
Date: Thu, 3 Oct 2019 01:38:53 +0200

Tomas Nordin <[email-masked]> writes:

> emacs -Q
>
> In the scratch buffer, eval each of the following:
>
> (require 'mailcap)
> (mailcap-mime-info "text/html") ;; -> "view %s"
> mailcap-prefer-mailcap-viewers ;; -> t
> (setq mailcap-prefer-mailcap-viewers t) ;; -> nil
> (mailcap-mime-info "text/html") ;; -> "/usr/bin/firefox-esr %s"
>
> I expect the result of mailcap-mime-info to be "/usr/bin/firefox-esr %s"
> when mailcap-prefer-mailcap-viewers is t because the doc of that
> variable says
>
>    If non-nil, prefer viewers specified in ~/.mailcap.
>    If nil, the most specific viewer will be chosen, even if there is
>    a general override in ~/.mailcap.  For instance, if /etc/mailcap
>    has an entry for "image/gif", that one will be chosen even if
>    you have an entry for "image/*" in your ~/.mailcap file.
>
> and
>
> $ cat ~/.mailcap | grep '^text/html'
> text/html; /usr/bin/firefox-esr %s; description=HTML Text; test=test -n "$DISPLAY";  nametemplate=%s.html
>
> What do you think?

Indeed, this seems to me like it's contradicting the doc string.

> If you agree this is a bug, I could provide that a bisect session gave
> me that it started to behave this way by commit
> 7e47d44da4b54c518c5e09b4f3d58dafdd43033d

Lars, that commit is yours.  What do you think?

I tried digging into this code, but found mailcap.el too confusing overall...

> In addition I am confused why mailcap-mime-info produces "view %s" in
> any case because
>
> $ cat /etc/mailcap | grep '^text/html'
> text/html; /usr/bin/sensible-browser %s; description=HTML Text; nametemplate=%s.html
> text/html; /usr/bin/firefox-esr %s; description=HTML Text; test=test -n "$DISPLAY";  nametemplate=%s.html
> text/html; gnome-builder %s; test=test -n "$DISPLAY"
> text/html; /usr/bin/w3m -T text/html %s; needsterminal; description=HTML Text; nametemplate=%s.html
> text/html; /usr/bin/w3m -I %{charset} -dump -T text/html %s; copiousoutput; description=HTML Text; nametemplate=%s.html
>
> I would naively think that the above would result in sensible-browser maybe.

Agreed.  Here I would have expected to get the more specific entry, but
I get the least specific entry.  On my system "view" in /etc/mailcap is:

text/*; view %s; edit=vim %s; compose=vim %s; test=test -x
/usr/bin/vim; needsterminal
text/*; view %s; edit=vi %s; compose=vi %s; needsterminal

Best regards,
Stefan Kangas