Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
    
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 Aug 22 '11 at 14:13
    
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 Aug 22 '11 at 17:20
    
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 Aug 23 '11 at 0:44
add comment

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.

share|improve this answer
    
this sudo mv /.Spotlight-V100 /Spotlight-V100-old help me a lot. thanks. –  pkyeck Jan 7 '13 at 19:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.