Viewing attachments when using mutt remotely

Yes, that’s right, I’m still in the dark ages and do not yet use Gmail for my email. Even though it has IMAP and everything. I still use Mutt.

I almost always use Mutt locally, using offlineimap to sync IMAP folders to local maildirs. This means I don’t usually have the problem of being unable to view non-text attachments. However, for the next little while I’ll be using Mutt on a remote connection.

Don Marti has one solution to this, which assumes that you are accessing the server with Mutt on it via SSH (probably true) and are easily able to create a tunnel to your local machine, which is trivial if you are using a commandline ssh client, but while you can do it with PuTTY I figured it was just annoying enough that I might not bother. (And I doubt you can do it at all with those web-based SSH clients.)

My alternative assumes instead that you have a webserver on the remote machine that has mutt on it. It then just copies the attachment to a web-accessible directory, and tells you the URL where you’ll be able to find the attachment. It’s thus a very trivial script (and I doubt very much it’s the only one out there), but perhaps using mine might save you fifteen minutes over coming up with your own, so here it is:

copy-to-dir.sh (in a bzr git repo)

Sample output is along these lines when you try to view an attachment in Mutt:

View attachment SOMEPDF.pdf at http://example.com/~user/SOMEPDF.pdf Press any key to continue, and delete viewable attachment

In order to use it, you need to:

  1. copy the script to the remote machine where you use mutt;
  2. make it executable;
  3. edit it to set the OUTPUTDIR and VIEWINGDIR variables to something that works for your setup;
  4. set up a custom mailcap file much like the one Don Marti gives, that is, put something like this in your ~/.mutt-mailcap:
     text/*; PATH-TO-SCRIPT/copy-to-dir.sh %s application/*; PATH-TO-SCRIPT/copy-to-dir.sh %s image/*; PATH-TO-SCRIPT/copy-to-dir.sh %s audio/*; PATH-TO-SCRIPT/copy-to-dir.sh %s
  5. set mailcap_path = ~/.mutt-mailcap in your ~/.muttrc file.

Something like this probably could work for Pine and other text-based email clients used remotely too, but I’m not sure how because I don’t use them. And if someone wants to document this in a way that assumes less pre-existing knowledge, go ahead.

Also, making your attachments web-accessible means that they are, well, web-accessible. I’ve set up a HTTP Auth-protected directory using https for this, you should think about your own setup too.

Creative Commons License
Viewing attachments when using mutt remotely by Mary Gardiner is licensed under a Creative Commons Attribution 4.0 International License.

Attaching messages to outgoing mail in mutt

When I want to forward an email to someone as an attachment (usually because I want them to reply to it without having to snip gunky forward ‘headers’ in the body and preserving Message-ID and such) I can’t always forward-as-attachment, sometimes because I’m replying rather than starting a new mail, sometimes because I’m forwarding messages from multiple folders.

Up until today, I’ve resorted to all kinds of tricks to add other messages as attachments to mutt messages. One old favourite was copying them (shift+c) to a new maildir, attaching the individual files and manually setting their MIME type to message/rfc822. This does actually work but there is an easier way, the attach-message function, bound to shift+a by default.

On the screen where you normally add attachments, press shift+a. Navigate to the folder containing the messages you wish to attach (if they’re in different folders, just do this once per folder). Tag all the messages you want to attach (the default keybinding for tagging a message is ‘t’). Quit from the folder browser (‘q’). All tagged messages will be attached to the outgoing mail.

Creative Commons License
Attaching messages to outgoing mail in mutt by Mary Gardiner is licensed under a Creative Commons Attribution 4.0 International License.

Sending messages one-by-one with mutt

Here’s a feature of my mail client, mutt, that I wasn’t previously aware of: the ability to emulate the mail command if you invoke it with mutt -x.

This is my use-case: every so often, I want to email a bunch of people, typically for some kind of invitation thing. But I’d like to email them the same message one by one.

I don’t want to Cc them all because I know a whole lot of people who are addicted to group reply/reply to all, and also because Gmail itself is addicted to this: it interprets mutt’s Mail-Followup-To header as Reply-To, meaning if I included an email list in the Ccs and mutt has set a Mail-Followup-To to be that email list and all other recipients minus myself (it’s been told I’m subscribed to the list), all Gmail users will reply to the entire Cc list minus myself, which is exactly the reverse of what I want. And lastly, occasionally I don’t want to give them a complete list of exactly who is and isn’t privy to whatever is in this particular email.

The standard solution is then to Bcc them. But most of my social mailing lists don’t accept Bccs, some of my friends also don’t accept them, and I also have trouble remembering who I sent the mail to.

After that, the typical thing to do (on the UNIX-like commandline anyway), is something like this:

  1. Store the text of the message in messagebody.txt
  2. Store the recipient list in addresses.txt
  3. Run a script that goes pretty much like this:
    for address in `cat addresses.txt`
    do
    mail -s “Some subject line” $address < messagebody.txt
    done

But then the problem is that I don’t have the usual copy of the outgoing mail in my mutt outbox, because I sent it with mail, not with mutt. However, just now I checked the mutt man page, and saw this:

 OPTIONS  -x     Emulate the mailx compose mode.

So, that means I can do this, or something equivalent to this, and get exactly the behaviour I want (mails sent one-at-a-time with the recipient’s email in the To: field and a copy left in my mutt outbox):

for address in `cat addresses.txt`
do
mutt -x -s “Some subject line” $address < messagebody.txt
done

Creative Commons License
Sending messages one-by-one with mutt by Mary Gardiner is licensed under a Creative Commons Attribution 4.0 International License.