View Mail Attachments from Mutt (Shallow Thoughts)

Akkana's Musings on Open Source Computing and Technology, Science, and Nature.

Sun, 18 Dec 2022

View Mail Attachments from Mutt

Back in 2015, I wrote a script for the mutt mailer (or any plaintext mail program, really) to view MS Word documents (or other unfriendly formats) attached to emails. (This is unfortunately something that comes up constantly in email exchanges with League of Women Voters people — many of them do everything in Word — so I needed a better way of dealing with it than going to the attachments screen, saving each attachment somewhere, then going to a separate window to LibreOffice on each of the saved files one by one.) My script runs unoconv to convert Word to HTML, then shows the HTML in a browser window, with multiple tabs if there are multiple attachments. I called my script viewmailattachments, and configured mutt so that hitting F9 would show all the attached documents; and I've been using it more or less daily since then.

I actually had a script I'd written a few years earlier to view HTML messages with their embedded images. You might think I'd make the Word attachment thing part of the same script; but honestly, I'd forgotten all about writing the HTML messages script, because it turns out I hardly ever get HTML mail with embedded images. None of my regular correspondents do that: the technophobic ones don't even know embedding images is possible, and the geeks write plaintext emails. So I really only needed viewhtmlmail for those "check out this bunch of funny images" messages that friends occasionally send.

In recent years, it's increasingly bugged me that I have two different unrelated scripts to do seemingly similar things (show the non-text parts of an email message), and that I have to think about whether this is an F9 sort of mail message or an F10 sort. A couple of weeks ago I finally did something about it: I integrated viewmailattachments and viewhtmlmail together into one script, The old script names, viewmailattachments (without the .py) and, are now just links to the new integrated script.

I also added some code to try to autodetect which browser to use: it tries qutebrowser first, then quickbrowse, then firefox. (Quickbrowse isn't first because I recently tried to port it to Qt6 and discovered that QtWebEngine in Qt6 isn't really supported, nor documented, and there are some things I couldn't get working, like multiple tabs. So I may have to abandon quickbrowse when Qt5 is discontinued.)

In mutt, I bind the script to the F9 key like so:

macro index <F9> "<pipe-message>/path/to/\n" "View all attachments in q browser"
macro pager <F9> "<pipe-message>/path/tp/\n" "View all attachments in a browser"
So now, if I want to see an email message in a format other than plain text, I can just hit F9 and trust that it will do the right thing.

Tags: , , , ,
[ 18:52 Dec 18, 2022    More tech/email | permalink to this entry | ]

Comments via Disqus:

blog comments powered by Disqus