- Move the file to a slightly more permanent location.
- Discern the file type and extension if not given.
- Don't do anything with the type if told to ignore it.
- Allow for an application to be specified.
- Open the appropriate application for the file
The next step is to edit your ~/.mailcap file so mutt can use the new program. The easiest entries are for images and pdfs, because their types are easily discernable. The mailcap entry for jpeg looks like this:
Image/JPEG;view_attachment %s
All this entry does is call the view_attachment program with the name of the temporary file that mutt wrote. view_attachment will discern the type and add or change the file extension so the Preview application will know what to do with it.
The next problem I had was with HTML files. Frequently, HTML mail does not have an extension. It is also not always discernable with the file command that does so well with images and lots of other file types. The mailcap file helps with this. It knows that the attachment is HTML. The solution is to tell view_attachment what the type is. That keeps it from guessing wrong. So the mailcap entry for HTML looks like this.
text/html; view_attachment %s html
The html after the %s tells view_attachment that the file type is html. view_attachment uses the type for the file extension. That ensures the proper application will handle it. Most likely that will be Safari.
The last problem was using a specific application for a specific file type. I use Open Office for a lot of different file types including Excel, Word, and PowerPoint files. Open Office is really good at figuring out what the file is, and doing the right thing. view_attachment doesn't need to do anything with the type. It could mess things up if it did. It still needs to move the file, though. The only other thing it should do is an open -a command with the application we asked for. That means two things.
- Type discerning needs to be turned off completely.
- There needs to be a third argument to specify the application
Application/vnd.ms-excel; /usr/local/bin/view_attachment %s "-"
'/Applications/OpenOffice.org1.1.2/Start_OpenOffice.org.app'
I changed the name of Start OpenOffice.org.app to Start_OpenOffice.org.app in my Applications -> OpenOffice.org1.1.2 directory. The space could have stayed, but it has to be escaped with a \, and that was more pain than I wanted to deal with. Here's my entire .mailcap file as an example to work with.

