The Mutt E-Mail Client : Mutt's MIME Support : MIME Viewer configuration with mailcap : Advanced mailcap Usage
Previous: Secure use of mailcap
Next: Example mailcap files

5.3.3. Advanced mailcap Usage

5.3.3.1. Optional Fields

In addition to the required content-type and view command fields, you can add semi-colon ';' separated fields to set flags and other options. Mutt recognizes the following optional fields:

copiousoutput

This flag tells Mutt that the command passes possibly large amounts of text on stdout. This causes Mutt to invoke a pager (either the internal pager or the external pager defined by the pager variable) on the output of the view command. Without this flag, Mutt assumes that the command is interactive. One could use this to replace the pipe to more in the lynx -dump example in the Basic section:

text/html; lynx -dump %s ; copiousoutput
This will cause lynx to format the text/html output as text/plain and Mutt will use your standard pager to display the results.

needsterminal

Mutt uses this flag when viewing attachments with autoview, in order to decide whether it should honor the setting of the $wait_key variable or not. When an attachment is viewed using an interactive program, and the corresponding mailcap entry has a needsterminal flag, Mutt will use $wait_key and the exit status of the program to decide if it will ask you to press a key after the external program has exited. In all other situations it will not prompt you for a key.

compose=<command>

This flag specifies the command to use to create a new attachment of a specific MIME type. Mutt supports this from the compose menu.

composetyped=<command>

This flag specifies the command to use to create a new attachment of a specific MIME type. This command differs from the compose command in that mutt will expect standard MIME headers on the data. This can be used to specify parameters, filename, description, etc. for a new attachment. Mutt supports this from the compose menu.

print=<command>

This flag specifies the command to use to print a specific MIME type. Mutt supports this from the attachment and compose menus.

edit=<command>

This flag specifies the command to use to edit a specific MIME type. Mutt supports this from the compose menu, and also uses it to compose new attachments. Mutt will default to the defined editor for text attachments.

nametemplate=<template>

This field specifies the format for the file denoted by %s in the command fields. Certain programs will require a certain file extension, for instance, to correctly view a file. For instance, lynx will only interpret a file as text/html if the file ends in .html. So, you would specify lynx as a text/html viewer with a line in the mailcap file like:

text/html; lynx %s; nametemplate=%s.html

test=<command>

This field specifies a command to run to test whether this mailcap entry should be used. The command is defined with the command expansion rules defined in the next section. If the command returns 0, then the test passed, and Mutt uses this entry. If the command returns non-zero, then the test failed, and Mutt continues searching for the right entry. Note: the content-type must match before Mutt performs the test. For example:

text/html; netscape -remote 'openURL(%s)' ; test=RunningX
text/html; lynx %s
In this example, Mutt will run the program RunningX which will return 0 if the X Window manager is running, and non-zero if it isn't. If RunningX returns 0, then Mutt will call netscape to display the text/html object. If RunningX doesn't return 0, then Mutt will go on to the next entry and use lynx to display the text/html object.

5.3.3.2. Search Order

When searching for an entry in the mailcap file, Mutt will search for the most useful entry for its purpose. For instance, if you are attempting to print an image/gif, and you have the following entries in your mailcap file, Mutt will search for an entry with the print command:

image/*;        xv %s
image/gif;      ; print= anytopnm %s | pnmtops | lpr; \
                nametemplate=%s.gif
Mutt will skip the image/* entry and use the image/gif entry with the print command.

In addition, you can use this with Autoview to denote two commands for viewing an attachment, one to be viewed automatically, the other to be viewed interactively from the attachment menu. In addition, you can then use the test feature to determine which viewer to use interactively depending on your environment.

text/html;      netscape -remote 'openURL(%s)' ; test=RunningX
text/html;      lynx %s; nametemplate=%s.html
text/html;      lynx -dump %s; nametemplate=%s.html; copiousoutput
For Autoview, Mutt will choose the third entry because of the copiousoutput tag. For interactive viewing, Mutt will run the program RunningX to determine if it should use the first entry. If the program returns non-zero, Mutt will use the second entry for interactive viewing.

5.3.3.3. Command Expansion

The various commands defined in the mailcap files are passed to the /bin/sh shell using the system() function. Before the command is passed to /bin/sh -c, it is parsed to expand various special parameters with information from Mutt. The keywords Mutt expands are:

%s

As seen in the basic mailcap section, this variable is expanded to a filename specified by the calling program. This file contains the body of the message to view/print/edit or where the composing program should place the results of composition. In addition, the use of this keyword causes Mutt to not pass the body of the message to the view/print/edit program on stdin.

%t

Mutt will expand %t to the text representation of the content type of the message in the same form as the first parameter of the mailcap definition line, ie text/html or image/gif.

%{<parameter>}

Mutt will expand this to the value of the specified parameter from the Content-Type: line of the mail message. For instance, if Your mail message contains:

Content-Type: text/plain; charset=iso-8859-1
then Mutt will expand %{charset} to iso-8859-1. The default metamail mailcap file uses this feature to test the charset to spawn an xterm using the right charset to view the message.

\%

This will be replaced by a %

Mutt does not currently support the %F and %n keywords specified in RFC 1524. The main purpose of these parameters is for multipart messages, which is handled internally by Mutt.


The Mutt E-Mail Client : Mutt's MIME Support : MIME Viewer configuration with mailcap : Advanced mailcap Usage
Previous: Secure use of mailcap
Next: Example mailcap files