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 and later (at least through Yosemite) it’s ~/Library/Mail/V2/MailData. Inside both of these folders are files that start with “Envelope Index” that store all your mailbox data, among other things.

Quit Mail, then delete all the files in this folder that start with "Envelope Index." On Yosemite that will be three (3) files (Envelope Index, Envelope Index-shm, and Envelope Index-wal); on older versions of OS X it may be simply one file. Once deleted, relaunch Mail and the file(s) 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!

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.

benji888578

I did a clean install of yosemite, and mail is still very slow sometimes. I have to open it, do something else for 5-10 minutes, sometimes longer (haven’t timed it, but feels like it), then see if it has caught up with itself. I had this issue before, thought it was from not doing a clean install since…Lion? I have 4 emails, 2 gmail, iCloud and one pop3 mail for website through godaddy. The longer I go without opening Mail app, the longer it takes to catch up. Or, if I open my mail on iOS devices, it takes time to catch up also. I wonder if this is an iCloud type of issue?

So, don’t be in a hurry, if you have gmail, it may just be very slow.

This has been an issue since Mavericks, maybe even Mtn. Lion. What is taking so long for apple to fix this?

Winski

On my MBP running OS/X 10.8.5, THERE IS NO /LIBRARY/MAIL folder that has ANYTHING in it… So am I looking in the wrong place?? I’m starting at the TOP of the file system….

Dave Hamilton

@Winksi — sorry about the confusion. In unix, the ~ means “home folder” — so start there and you’ll find it.

furbies

<quote>
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
</quote>

Dave you might want to edit the
“For Lion, it’s:”
to
“For Lion and newer, it’s:”

Log-in to comment