August 2, 2017 - Bryce Harrington

Better Attachment Handling with Mutt

The Mutt email client is famed for its extensive configuration options, but since it’s text-based, certain things are more challenging to do when compared to its graphical brethren. Viewing attachments is one such annoyance; fortunately, as with most things, Mutt is extensively configurable!

By default, Mutt does fine with most plain text documents, and depending on your installation may also handle HTML documents in some fashion. Attachments that Mutt doesn’t recognize can of course be downloaded and viewed manually, but we can do better.

To tell Mutt that it should handle a new attachment type, or its “MIME type”, we associate it with Mutt’s “auto_view” parameter. For example, add this to your ~/.muttrc (and restart Mutt):

Note: if you plan to add a number of file types, you may wish to put these in their own config file (e.g. ~/.mutt/auto-views), and include a line in ~/.muttrc like the following:

A typical Linux system will include a pretty broad range of MIME type definitions (see /etc/mime.types). If you need to augment that list, or override the default definitions, you can add custom types to a ~/.mime.types file, such as:

To specify how Mutt should display these file types (and other text interface programs), add the following to ~/.mailcap:

The ‘copiousoutput’ flag should be added for all commands that are likely to produce more than a handful of lines and that are display-only, requiring no interaction with the user. This will trigger the use of your desired pagination program (e.g. ‘more’) for scrolling through the output.

For mimetypes that are already a plain text format, requiring no further processing, the ‘cat’ command is sufficient. Some mimetypes are directly convertible into text, via commands like zcat that can accept a filename argument. For commands that only accept input through their STDIN, you can construct a shell command with the filename indicated by %s, for instance “pgp -f < %s”.

In some cases, the mimetype is not directly convertible to plain text, and you’ll need a more sophisticated command line sequence or script. For example, while text/calendar files are plain text, the raw data is rather dense and not always expressed in the time zone we care about, however it is easy enough to translate with a short python script:

Save this to a file named and change it to be executable:

Now, when viewing a calendar invitation you will see a nicely printed summary of the event with dates and times converted to your local timezone. These tips should help you get more out of Mutt, if you have any questions or tips of your own, feel free to post them in the comments below!

Bryce Harrington

About Bryce Harrington

Bryce Harrington is a Senior Open Source Developer at the Samsung Open Source Group focusing on Open Source Graphics. Prior to Samsung, he lead Canonical, Ltd.’s Ubuntu team, and focused on stabilization of the graphics and input infrastructures for the Ubuntu distribution. Bryce began his career in the aerospace industry as a spacecraft propulsions engineer at The Aerospace Corporation, Hughes Space and Communications and TRW. Later, he joined the Open Source Development Labs as a Senior Performance Engineer working on NFSv4 testing and development of automated test systems. He is a founder and developer of the Inkscape project and serves as Chairman of the Inkscape Board. Bryce has a BS-AE from USC and an MS-AE from Caltech.

Development / Linux Email / Mutt /

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments Protected by WP-SpamShield Anti-Spam