Restore IMAP mail from local cache via Time Machine

I had a real scary moment last night. I was cleaning off my server and deleted the home directory for my databasically email account. I don't host the website on that server, so I thought removing the home directory would be fine. However, I do host the mail on that server and it's stored in the home directory.

I had Apple running and connected to that mailbox. I didn't really notice it until a few minutes later when a message came in on another account.

My work account was blank. Empty. Also, I had a nice exclamation point saying the account couldn't be found.

Whoops. Oh hell.

I have my computer hooked to an external hard drive which I'm using as my Time Machine (the built-in Mac backup software) drive. I poked through the folders from an hour ago and found all my mail.

The mail is stored in ~/Library/Mail/, where each IMAP account has a folder called IMAP-user@host. This folder contains many folders with the .imapmbox extension.

Here's how I restored my mailbox:
  • Recreated my home directory and made sure that the email address still worked. You may want to set up a new account if you're moving hosts or whatever. Get a working IMAP account up and running.
  • Put the IMAP-user@host folder to my Desktop. Actually, I restored it from Time Machine and then copied it to the Desktop. I selected "Keep both" when doing the Time Machine restore which renamed my existing folder to end in "(original)". I moved the restored folder to my Desktop and removed the "(original)".
  • Renamed each folders' extension from .imapmbox to .mbox . Make sure you get any subfolders as well.
  • Import the file: File > Import Mailboxes > Mail for Mac OS X
  • Select the parent folder (IMAP-user@host) containing all your .mbox files.
  • Your mail will be imported to a folder named Import inside the On My Mac folder.
  • Drag your mail to your new/restored IMAP mailbox. I copied 5000 messages at a time without an issue.
Hopefully you never need this information.

If it helped you out or if you have any other information, please let me know in the comments.

Established 2005 · Databasically © 2016