Bulk archiving to GMail using mutt • Gated Logic • nevali.net

mutt, despite its lack of graphical glitz, is an exceptionally powerful e-mail client. One little-known feature is its support for IMAP, which means it will happily talk to GMail. Usefully, transferring messages between mailboxes in mutt is very smooth indeed.

As an example, I’m going to move a mailbox full of messages that I archived from Mail.app, as per my tip yesterday. The messages were archived to ~/Desktop/Archive.mbox. mutt will read mbox and Maildir-format mailboxes (and possibly some other kinds, too), so these instructions will apply equally—just adjust the paths to suit. In my setup, I’ve got mutt installed on my Mac, but you could easily transfer an mbox file to a remote machine if it makes life easier.

  • Fire up a terminal and run mutt.
  • Press g to go to a mailbox. Enter the path to the mbox file or Maildir directory—in my case, it’s ~/Desktop/Archive.mbox/mbox.
  • Press Shift+T, and then type .* to tag all of the messages in the mailbox.
  • Press a (apply) and then s (save). Next you’ll need to enter a URL for your GMail account. These take the form: imaps://username@imap.gmail.com/Label, where “username” is your GMail username (which might be username@yourdomain.com if you use Google Apps), and Label is a pre-existing label (folder) to assign to all of the imported messages.
  • mutt will prompt you to accept the SSL certificate. You probably want to.
  • Sometimes GMail’s IMAP server is a bit flakey and drops the connection; if this happens, mutt will halt the transfer process. mutt always processes messages in mailbox order, and deletes messages after they’ve been saved to another folder. To carry on where you left off if the connection is dropped, press x (eXpunge) to permanently delete the messages that have already been transferred, and then press a s again to save the tagged messages. You can use the up arrow key to navigate the mailbox history to find the GMail URL you entered earlier.