Mutt, using document viewers

Mutt can start document viewers following the system configuration in

  • /etc/mime.types
  • /etc/mailcap
but starting a document viewer is not always enough to actually view the configured document types.



Modern document viewers return control to mutt just after starting, causing mutt to suppose that you are done reading the document and to remove the temporary file holding the document. Most document viewers do not expect this behaviour and fail to display the contents.

You will need some special handling for mutt which you could configure in

$HOME/.mailcap
but this will also be followed by other applications that cannot cope with the proposed handling below. So create a mutt-specific mailcap, for example:
$HOME/.mailcap_mutt
and point mutt to this .mailcap_mutt by adding
set mailcap_path = $HOME/.mailcap_mutt
to $HOME/.muttrc .

As an example for pdf, add the following entry to $HOME/.mailcap_mutt :

application/pdf; { set -m \; /bin/mv -T %s %s.mv \; ( evince %s.mv \; /bin/rm %s.mv \; ) & } \; disown -a
all on one line and including all of this line ending in disown -a (you may need to scroll in your browser window) and including all of the spaces, especially those
  • after {
  • before }
This should cause mutt to display pdf-documents as expected:
  • You can proceed using mutt without closing the document
  • Temporary files are removed
  • Suspending mutt (using ^Z) does not suspend the document viewer

Applications such as acroread write messages on the mutt screen. You probably do not like that, so redirect to /dev/null:
application/pdf; { set -m \; /bin/mv -T %s %s.mv \; ( acroread %s.mv >/dev/null 2>&1 \; /bin/rm %s.mv \; ) & } \; disown -a

How does it work

If you want to know why the one-liner is supposed to do the job, why it needs to be like this and why it needs to be a one-liner at all, read the following comment and prepend it before the one-liner:
# I need to meet some requirements...
# - application/xxx must be a one-liner
# - we want to run evince as a background process
# - mutt removes %s immediately if evince (it's invoking shell) returns
# - evince cannot display the removed %s although it keeps the filedescriptor
#
# ...but there is also a piece of luck:
# - mutt does not mind removing a not existing (renamed) %s
#
# Implementation details:
# - -m prevents stopping evince when stopping (^Z) mutt
# - -m introduces evince exit status notification
# - disown -a undoes the exit status notification
# - mv must be done before going to background mode, else mutt could rm first
# - acroread logs to stdout, that is, the mutt window: redirect to /dev/null


Contact us | Webmaster

Questions? Mail to helpdesk.win@tue.nl