How to Clean Up and Rebuild Apple Mail Data

| MGG Answers

Question:

Joe writes: My Apple Mail mailboxes appear to have become corrupted; when I click on a mailbox in Mail, no messages appear. Following the instructions in Mail’s help files, I used the Mailbox > Rebuild command on an individual mailbox and it solved the issue.

My problem is that I have hundreds of mailboxes and it would be too time consuming to perform this step on each box individually. Is there a way to perform the rebuild command on all my mailboxes at once?

Answer:

Mail Mail Mail!

MAIL MAIL MAIL!

There are two methods to rebuild your entire mail library, including all of your mailboxes. The first is to navigate to a folder in your user directory. In Snow Leopard, this folder is ~/Library/Mail and in Lion it’s ~/Library/Mail/V2/MailData. Inside both of these folders is a file called “Envelope Index” that stores all your mailbox data, among other things.

Quit Mail, then delete this file. Once deleted, relaunch Mail and the file will be rebuilt, along with your mailboxes.

The second method involves using Terminal. Open up Terminal and type the following command using the correct path for your operating system. For Lion, it’s:

sqlite3 ~/Library/Mail/V2/MailData/Envelope\ Index vacuum 

For Snow Leopard, the command is:

sqlite3 ~/Library/Mail/Envelope\ Index vacuum

Remember, you should only have to perform one of these methods, not both. That should solve your problem and rebuild all of your mailboxes.

This question was originally answered on MGG 365: Building Mac & iOS Apps, Cleaning Mail, Taming Spotlight

About MGG Answers:

Each week Dave Hamilton and John F. Braun provide some great troubleshooting advice to listeners of the Mac Geek Gab podcast. Here with MGG Answers we share some of those tips with the rest of the world!

Sign Up for the Newsletter

Join the TMO Express Daily Newsletter to get the latest Mac headlines in your e-mail every weekday.

2 Comments

James

I get an error in Lion when using the terminal command.

“sqlite3: Error: too many options: “index”“

Dave Hamilton

James, check the command. It sounds like you’re not putting the backslash in before the space prior to the word ‘Index’ and, therefore, the Terminal is treating ‘Index’ as a separate part of the command instead of part of the file name.

Log-in to comment