Shell script to enable easy viewing of attachments from mutt on OS X
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Shell script to enable easy viewing of attachments from mutt on OS X

Purpose: To be called by mutt as indicated by .mailcap to handle mail attachments.

Function: Copy the given file to a temporary directory so mutt Won't delete it before it is read by the application.

       Along the way, discern the file type or use the type
       That is given.

       Finally use 'open' or 'open -a' if the third argument is


 $1 is the file
 $2 is the type - for those times when file magic isn't enough.
                  I frequently get html mail that has no extension
                  and file can't figure out what it is.

                  Set to '-' if you don't want the type to be discerned.
                  Many applications can sniff out the type on their own.
                  And they do a better job of it too.
                  Open Office and MS Office for example.
 $3 is open with.  as in open -a 'open with this .app' foo.xls

Examples: These are typical .mailcap entries which use this program.

Here are chunks from my original .mailcap file when I wrote view_attachment. Using Numbers, and pages works equally well.

MS Excel

Application/x-msexcel; view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/' Application/ms-exc; view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/' Application/excel; view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/' Application/msexcel; view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/' Application/; view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/' Application/; view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/'

MS Word

Application/msword; view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/'

MS PowerPoint

application/powerpoint; view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/' application/mspowerpoint; view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/' application/; view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/' application/x-mspowerpoint; view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/'


Image/JPEG; view_attachment %s Image/PJPEG; view_attachment %s Image/PNG; view_attachment %s Image/GIF; view_attachment %s text/calendar; view_attachment %s ics


Application/octet-stream; view_attachment %s "-"


Application/PDF; view_attachment %s pdf