Archiving old mail with formail

I’ve been trying to clean up my email at work lately. When a new project comes in, I create an email folder for it in MailMate and then save the incoming and outgoing messages associated with that project in the folder. When the project is finished, I’m faced with four options:

  1. Delete the project folder and its messages. This gets rid of the messages on both the server and my local computer. I don’t like doing this because you never know when a client is going to come back asking for information that’s squirreled away in an email.
  2. Move the project folder into an “Old projects” folder. This preserves the messages on both the server and my local computer, but keeps the MailMate interface cleaner by hiding folders I don’t expect to access. The problem with this is that messages accumulate on my local computer—not a concern with for the iMac with a 3 TB hard drive, but a bit of a squeeze on my old MacBook Air with only a 128 GB SSD.
  3. Go into File‣Edit IMAP Account‣Server Name and change the subscription settings for the project folder.

    MailMate subscription setting

    This keeps the messages on the server but allows my local computer to reclaim some disk space. And I can always change the setting back temporarily if I need to get at the old messages.

  4. Archive the messages in mbox format, save the archive with the rest of the old project files, and delete the project folder and its messages. This gets rid of the messages from both the server and my local computer, but preserves them along with the rest of the file materials in an offline archive.

Choice 4 is my preference, with Choice 3 coming in a close second. Unfortunately, MailMate—which I switched to when Mail.app on Mavericks refused to collect mail from the GMail servers on a regular basis—has no Export command, so I’ve been forced to go with Choice 3 since early last year. But today I found the formail command, and it looks like I can return to archiving and deleting.

I learned about formail from this Stack Exchange page, in which the questioner wanted to be able to open an email stored in eml format in Mutt. The top answer used formail to convert the eml into mbox so Mutt could open it. MailMate stores its messages in eml format, so it took only a little messing around to adapt the answer to handle a folder full of messages in eml format.

Here’s what I do to make an mbox archive:

I’ve tested this command several times on different mail folders, and it’s always worked well. The easiest way to test is to open the mbox file in Mutt:

mutt -f test.mbox

which, if it works, leads to something like this:

Viewing mbox file in Mutt

Mutt isn’t shipped with OS X, but it’s easy to install through Homebrew. I’m sure there are other ways to test an archive, but I was a happy Mutt user back in my Linux days, so that’s what I thought of first.

formail is part of the old Unix procmail system. I was a procmail user in my Linux days, too, but definitely not a happy one. Only a masochist could enjoy editing a procmail recipe.

Update 9/4/15 4:07 PM
Some followup comments here.