Recreate Mail.app Search Index?

3

1

It seems that the search index for my Mail.app has been corrupted. I have 4 years of emails, but when searching via the built-in search in Mail.app it always returns no results. Anyone have any idea how the search index can be rebuilt or recreated in Mail.app on OS X?

Mahmoud Al-Qudsi

Posted 2011-08-18T05:51:34.723

Reputation: 3 274

Answers

5

Prior to Lion Mail keeps its database at ~/Library/Mail/Envelope Index. For Lion it's ~/Library/Mail/V2/MailData/Envelope Index.

It's a sqlite database. To regenerate the entire file simply quit mail then delete the file. Mail will create a new one at next launch (it may take a while depending on the size of your mailboxes).

Caveate: I've only done this prior to Lion. I see in my MailData directory there are several files on Lion I'm not familiar with, so it may behave differently. You're responsible for backing up your own data before nuking anything.

bahamat

Posted 2011-08-18T05:51:34.723

Reputation: 5 130

Right, but this is the actual Mail database, correct? As in, all the emails and so and so forth. I wouldn't want to delete that, just the search index.

I guess I could open the sqlite database and trawl through it hoping to find a search table that I could clear, but that would be uber-risky in the extreme... – Mahmoud Al-Qudsi – 2011-08-22T14:13:47.623

No it's not all the email messages themselves. Those will all be in a directories named after your account. E.g., IMAP-username@imap.gmail.com. – bahamat – 2011-08-22T17:20:43.430

Worked a treat. Thanks. Sorry about the confusion, I had read a very similar solution on another site that would have had me delete the entire inbox. – Mahmoud Al-Qudsi – 2011-08-23T00:44:25.620

1

If the ~/Library/Mail/Envelope Index trick does not work, which it did not for me there are a number of other steps one can take to rebuild the mail search index, some outlined here: http://www.chriswrites.com/2012/02/find-missing-emails-in-mac-os-xs-mail-app/

  1. try mdimport -r /System/Library/Spotlight/Mail.mdimporter in the Terminal

  2. try sudo mdutil – E in the Terminal (admin password required), or via the Spotlight preferences, add the whole computer to the 'Privacy' list of excluded folders, then remove it; both actions will force a recalculation of the spotlight index

  3. in my case, all the above failed to do anything, and I got an error message when trying to change the Spotlight privacy settings, indicating my whole index was really messed up. The solution was to type the following in the Terminal:

    sudo mv /.Spotlight-V100 /Spotlight-V100-old

    and then restart the computer, to force a reindex of the machine. You can also then clean up the folder "Spotlight-V100-old" that will now appear on your hard drive.

    This third nuclear option also requires admin privileges.

charles

Posted 2011-08-18T05:51:34.723

Reputation: 121

this sudo mv /.Spotlight-V100 /Spotlight-V100-old help me a lot. thanks. – pkyeck – 2013-01-07T19:46:43.313