Categories
Email Linux OS/Software Technology

Using mutt on Linux to transfer your old mbox mail folders onto GMail

Unlike many webmail providers, Google don’t allow you to upload your folders from your old mail system in mbox format and import them. This is a pretty basic feature if you ask me, they really should.

There are a number of alternative ways. GMail does support fetching from other mail servers via POP3 (but not IMAP, another strange omission), so if your mail is all in your inbox at the old place that might work, but mine is organised into several folders, and I want to keep that organisation damnit!

Needless to say, someone has written a nice piece of software to do the job; in this case Mark Lyon’s GML. I was about to give this a whirl, but while I was waiting for the requisite Python lib to install, I found a much simpler way… click to read on…

I noticed an instruction on the download page of the old version, to the effect that users of the noddy console-based email client PINE should forget GML and follow a linked set of instructions. I don’t use PINE (except at gunpoint), but as a general rule, anything that PINE can do, my more hardcore console-based email client, Mutt, should be able to do too (and better, of course 🙂 )

The link from the GML site was dead but a quick Google found it here. In 2 seconds I realised what it was saying, and knew it was the patently obvious solution that I wouldn’t have thought of in a million years.

Mutt and PINE both have the ability, sadly missing from many other mail clients, to bounce a mail. That’s not the same kind of bounce as a bounce message informing of non-delivery; what it means is that the mail is simply re-sent, exactly as is, to a different address. Everything about the message, including the headers, is left alone. Contrast this with the more common act of forwarding, which typically places the message body and *some* of its headers into the body of another message. The great advantage of bouncing is that because the original headers are intact, the receiving system will display the mail with its original date and time rather than when it was forwarded; its original sender and recipient addresses rather than those required to forward the message, and so on. In other words, bouncing preserves the original metadata[1]

Mutt and PINE also both have the ability to select multiple messages, and apply any action to those selected. So the basic idea is to select all the messages in the mbox, and bounce them to the new address. Here’s the difference. In PINE, you have to enable bouncing in the config screen, then select all messages, and bounce them. In Mutt, you just do this: [T] [.] [enter] [;] [b] followed by the email address. Don’t type the square brackets, just the keys inside them. The [T] is a capital T so really it’s [shift][T]. Whereas the [b] is lowercase, unshifted.

First things first. Before you go bouncing thousands of messages, make sure you can send a test mail from the system where your mbox files are, to your chosen email address, and that it arrives where you expect!

Now for each folder, load mutt with the relevant mbox file like this:

mutt -f /path/to/mboxfile

Then from the index screen showing all the messages, type the following letters: You’re merely entering two simple commands:

T (uppercase T, ie shift-t) Tag messages matching the following pattern:
. (dot, full stop, period) Regular expression (regex), will match any message containing at least one character in its headers (that should be all of them – even if a message has a blank Subject, it still matches this pattern). Press enter to finish entering the regex.
At this point, all the messages in the folder should be tagged with a *
; (semicolon) Apply the following command to all tagged messages (ie all messages in this folder)
b (lowercase B) Bounce message to… (prompts you for email address)

For GMail, all the mails will wind up in your inbox regardless of how you had them arranged into folders previously, so the thing to do is bounce over one folder at a time, then label them in GMail, archive them, then proceed to the next one.

Shout to Oliver Aaltonen for the original PINE tip. Incidentally, that one might be additionally useful if your old mail is on an IMAP server, because PINE deals quite elegantly with IMAP.

[1] All the message metadata is preserved, in fact, except the “envelope sender”, which is the value the sending server gave in its SMTP conversation with the receiver, in the MAIL FROM: command). It seems unlikely you’ll ever need to know that, but keep the original mbox files anyway for the (far more likely) possibility that you, or GMail, may lose some of your messages one day…

2 replies on “Using mutt on Linux to transfer your old mbox mail folders onto GMail”

Leave a Reply

Your email address will not be published. Required fields are marked *

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