Viewing docx attachments in mutt
As many know, I am a serious fan of running as many programs as I can in a terminal. This is so that I can embed them in tmux (I used to use GNU/Screen, but since switched to this new contender, and recommend you check it out!) and therefore be able to re-attach to a remote tmux session on one of my servers and access all my programs exactly how I left them, no matter where I am.
One of the programs I use in a tmux session is mutt, a mail client. Mutt is insanely fast, full of useful shortcuts, has GPG support, and various other features that I like.
However, one pitfall of running your mail client remotely is that it can be difficult to handle attachments sent to you, that would otherwise normally get detected by your local OS by preference or mime and fire up the relevant program to view it.
For things like pdf viewing, there's useful tools like pdf2text that you can put in your ~/.mutt/mailcap file to view pdf's from the command line. Images, I simply don't care about (usually). But recently someone sent me a Microsoft docx file, and I needed to work out how to view it.
(Initially I fired up a GUI mail client, thinking it was time to change my diehard habits, but it was just too hard. And sloooooooooooooow. Just can't go past mutt!)
The answer came in the form of antiword-xp-rb, a ruby program inspired by another tool I discovered in the Debian repositories, antiword. Antiword (and Antiword-XP.rb) convert doc files to text. Perfect. The only issue with the older antiword was that it doesn't seem to support .docx files from more modern Microsoft Word versions. That's where antiword-xp.rb comes in.
I simply git cloned it and dropped the .rb file into /usr/local/bin. It depends on ruby, rubygems, and the zip rubygem.
This is my portion of the mailcap for handling doc files:
application/msword;antiwordxp.rb %s | less ; nametemplate=%s.doc; copiousoutput application/vnd.openxmlformats-officedocument.wordprocessingml.document; antiwordxp.rb %s | less ; copiousoutput
Magic! Now I can easily view doc and .docx files over mutt without having to resort to using any other programs.
Now to find a tool that auto-converts jpgs and things to ASCII :)

Add new comment