Mutt: Mailbox power tool

M

Milestone_1_6_–_Mutt

“All mail clients suck. This one just sucks less.”

Mutt is a commandline mail client that’s been in use and been actively developed for about two decades. It’s considered by many to be the most powerful mail client available, particularly for handling large volumes of email. It’s weaknesses include poor rich text handling and desktop integration for attachment handling – which led to it losing market share to GUI mail clients.
But it’s still a very powerful client. And, particularly if you use IMAP, you don’t have to use a single mail client for everything. If you find yourself needing to do complex bulk operations on a mailbox, and your regular GUI client isn’t up to it, consider using Mutt.
I found myself with 116,000 messages in my inbox. (I’ve heard of inbox zero, but it doesn’t really suit my workflow). Mail.app starts to misbehave with large mailboxes – losing track of messages – and it can’t handle moving tens of thousands of messages from an inbox to an archive mailbox without crashing. Nor could several other GUI mail clients I had handy.
Time to pull out mutt to perform some mailbox surgery.
I’m on OS X, and have homebrew installed, so installing mutt was as simple as “brew install mutt“. Any unix system will have it available as a standard package (if it’s not already installed), and there’s some support for installing it on Windows.
You can configure it to talk to your IMAP server like this, if your server uses TLS. Copy this into “~/.muttrc

set spoolfile="imaps://steve:passwd@mx.wordtothewise.com/INBOX"
set folder="imaps://steve@mx.wordtothewise.com/"
set header_cache="~/.cache/mutt/headers"

You’ll need to set your username, password and the hostname of your IMAP server in the first two lines. The third line just configures mutt to cache message metadata locally – it’s not essential, but it makes switching between large folders somewhat faster.
Then run “mutt” and wait for it to connect to your IMAP server and open your inbox. Mutt is controlled almost entirely with single keypresses. “?” will show help. Page-up, page-down will scroll through text or mailboxes. The top line of the screen will show a few useful keys, including how to exit out of the current page.
You can list available mailboxes by typing “c?“. From there you can use the arrow keys and return to select a mailbox and open it, or you can use “C” to create a new (IMAP) mailbox.
When you’re in a mailbox you can scroll through it with the arrow keys, use “/” to search or type a number to go to that message in the mailbox.
So far, nothing particularly different to any other mail client. Where things get interesting is when you start using tagging to perform bulk operations.
You can tag or untag an individual message with “t“. Tagged messages will be shown with a “*“. Much more powerful is the tag pattern command, “T“. When you hit “T” mutt will give you a prompt: “Tag messages matching:”. From that prompt you can use any of the patterns shown in the mutt manual to tag multiple messages.
I wanted to select all my mail from 2012 and earlier, to move it to an archive mailbox, so I entered:

Tag messages matching: ~d -31/12/2012

That tagged a few tens of thousands of messages.
Then I used the “tag-prefix” command, followed by the “save” command to save (move) all the tagged messages to a new mailbox. “;s?” – the semicolon is the tag-prefix command, meaning “do the next thing to all the tagged messages”. “s” is “save”, meaning copy a message to a new location then delete the original (most mail clients describe this as “move”, but when in muttland …). The “?” opens a list of mailboxes to choose from.
I want to move everything to a new mailbox, so I type “C” and give it the name “archive2012” to create a new mailbox. Then I move the cursor to that new mailbox and hit return to start the “save” operation.
A few seconds later and all the messages have been moved. They’re still visible in the inbox, but marked with a “D” flag to show they’ve been deleted. I can use the purge command, “$” to completely remove them right away, or I’ll be prompted to purge them when I leave the mailbox.
Throughout this process Mutt hasn’t downloaded any of the messages to local disk, just a cached copy of the message headers. And all the copying of messages was done by moving them directly on the IMAP server, not by downloading and reuploading them – so everything was fast, or as fast as the IMAP server can be, and it didn’t use much local disk space.
It takes a little effort to learn how mutt works, but it’s an incredibly powerful tool for manipulating mailboxes, particularly via IMAP. Browse through the patterns section of the mutt manual to get some idea of it’s power.
 

About the author

4 comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Any idea on whether it’s possible to use a public key to connect to the IMAP server, so that I wouldn’t have to save the password in plaintext in my .muttrc file.

  • Leave out the colon and password and it’ll prompt you when you run Mutt.
    But if you are worried about Nasty Thing reading random files from your disk and sending them to a Bad Place, you have other problems 🙂

  • That’s true of course.
    Having it prompt my password every time is a tad annoying; public keys could solve that, without exposing the password. But I guess in practice, it’s probably not much more secure.

  • Martijn, that’s not a Mutt-specific issue. Does your IMAP mail server support logging in with anything else but a password? If it does, chances are that clients (one or more, somewhere) support the feature.

By steve

Recent Posts

Archives

Follow Us