Mailcap file for mail client mutt

Posted by Eric Scheibler at August 8, 2013

This article contains my mailcap file for the console mail client mutt. With the defined rules in the file it’s possible to open PDF, DOCX, HTML and other documents in mutt directly.

You must copy the mailcap file to the folder ~/.mutt and restart the mail client. After that you can open a mail attachment by navigating to the mail in the index view and pressing “v”.

Download: mailcap

# mailcap file for mutt
# Author: Eric Scheibler
# Last update: 2022-08-03
#
# copy into ~/.mutt/
# then add the following lines to ~/.mutt/muttrc
#   ```
#   set mailcap_path="~/.mutt/mailcap"
#   bind attach <return>    view-mailcap
#   ```
#
# general hint
# find out unknown file extension mime type:
# in the mutt index view, go to the mail and press "|"
# then enter the command: grep Content-Type

# .txt
text/plain;                 cat %s; copiousoutput

# .html
# sudo aptitude install w3m
# interactive: open in w3m from attachments menu to click links in emails
text/html;                  w3m -T text/html -O utf-8 %s;
# non-interactive: used in auto-view and reply
text/html;                  w3m -dump -T text/html -O utf-8 %s; copiousoutput;

# .rtf
# sudo aptitude install unrtf
application/rtf;            unrtf --text %s; copiousoutput
text/rtf;                   unrtf --text %s; copiousoutput

# .pdf
# My ocr script extracts text from pdf and images:
# Link: http://eric-scheibler.de/en/blog/2015/04/script-to-extract-text-from-images-and-scanned-pdf-files/
application/pdf;            ocr -r layout -s %s; copiousoutput
application/vnd.fdf;        ocr -r layout -s %s; copiousoutput
# or use pdftotext:
# sudo aptitude install poppler-utils
#application/pdf;            pdftotext -q -layout %s -; copiousoutput
#application/vnd.fdf;        pdftotext -q -layout %s -; copiousoutput

# images
image/*;      ocr -s %s; copiousoutput

# calendar (.ics)
text/calendar;      khal import -a calendar %s;
text/X-vCalendar;   khal import -a calendar %s;


# open office

# .odt
# sudo aptitude install odt2txt
application/vnd.oasis.opendocument.text;                                    odt2txt %s; copiousoutput


# microsoft office

# .doc
# sudo aptitude install antiword
application/msword;         antiword %s; copiousoutput

# .docx (since Office 2010)
application/vnd.ms-word.document.12;                                        pandoc -f docx -t plain %s; copiousoutput
application/vnd.openxmlformats-officedocument.wordprocessingml.document;    pandoc -f docx -t plain %s; copiousoutput

# .xls
# sudo aptitude install catdoc
application/vnd.ms-excel;   xls2csv -x %s -s cp1252 -d utf-8; copiousoutput