Fix Mail.app Search Issues and Speed Up Apple Mail with This Simple Script

by Michael Sheehan on January 4, 2010

in Apple, Fix It, General, HTD Tech Tip, Software

Today I was trying to find an email in my Apple Mail and went to my usual trustworthy internal mail search function only to find that the “Entire Message” field was grayed out for all of my accounts. Granted, I use a mixture of POP3 and IMAP account and my main IMAP account has about 8400 messages in my inbox (hmm, maybe I should start filing those?).

After doing some quick searches, I came across a little script or command that you can run in the Terminal which helps to optimize your email subject lines. In fact, after reading through some of the comments on this post which talks about the process, you can run the same command of “vacuum” on a variety of the tables within your Mail.app database (e.g., addresses, messages, attachments, threads, etc.).

The Script

Here is the simple script that you can run:

  1. Exit out of your Mail application
  2. Launch Terminal (if you don’t know what this is, you might want to just get the Automator script that is linked below).
  3. Type in the following:
    cd ~/Library/Mail
    sqlite3 Envelope Index
  4. You will see a new prompt that says “sqlite>”
  5. At the prompt, type (don’t forget the semi-colon):
    vacuum subjects;
  6. It may take a few seconds (it took mine a while) for the script to run. This depends on the size of your mail database
  7. When the script has finished, you will see the “sqlite>” prompt again.
  8. Push CTRL-D to exit out of sqllite.

That’s all that you have to do. You will definitely see some improvements in your Mail application speed. Also, this corrected the error that I found with the “Entire Message” field being dimmed out. Corrected resulting image shown below:

Additional Cleaning

I read through some more of the comments and one user commented that you can also “vacuum” other tables. I have not tried that so let me know what the results are if you try it. To do that, after the “vacuum subjects;” command, simply type:

vacuum addresses;
vacuum messages;
vacuum attachments;
vacuum threads;

There are some other tables in there (like “properties”) but I think the ones above are the most critical.

Automate It

Lastly, you can download an Automator script that can do this for you automatically. And, you might even want to tie it to a Calendar event to run every month or so. The Automator script can be downloaded here. From what I can tell, it simply runs the “vaccum;” command on everything. To set up the Automator script based on a calendar event, do the following:

  1. Download Mail Vacuum 1.1
  2. Unzip and move the Automator script somewhere where you can save it (e.g., the “Applications” directory)
  3. Open the script in Automator
  4. Choose “Save as” and then select type “Application”
  5. Exit Automator
  6. Launch iCal
  7. Create a new Event
  8. Under the Alarm section, choose “Open File”
  9. Choose the Automator Application you just created.
  10. Set up a repeating event (optional) – I set mine to repeat monthly for a year.

From my understanding, the SQLite “vacuum” cleans up the main database “by copying its contents to a temporary database file and reloading the original database file from the copy.” This does some essential database optimizations. More details on the SQLite “vacuum” command can be seen here.

Did you find this solution useful? If so:

HTD says: Let me know how this tip works for you! It definitely fixed my Mail.app search problems!

Print Friendly
  • Pingback: Tweets that mention Fix Mail.app Search Issues and Speed Up Apple Mail with This Simple Script | HighTechDad Blog -- Topsy.com

  • http://twitter.com/kd6ftr Mike (kd6ftr)

    Awesome! I edited/tested the vacuuming of the other indeces and Mail smokes now! I thought I was doomed to slowness. Not anymore.

  • http://centerforward.com/ Alan

    Hey everyone,

    I stessed about this for a week and jailbreak/terminal type fixes like above were not working, just found this on APPLE’s iphone forum, nothing to do with jailbreaking:

    ————————————————————————
    http://discussions.apple.com/thread.jspa?messag

    hi,

    I had the same problem and resolved it easy.
    If you have more accounts, find out wich one is causing the problem by going in to settings – E-mail and switch them of one by one.

    Found it, go into mail’s trash and delete all mails.

    That did it for me.

    If problem comes back after sync, in mail settings choos – show 25 recent, and delete on your computer mail account first 25 mails and trash to.

    Prob. you sended a photo from your iphone resently and the phone found it some how to be corrupt.
    ————————————————————————

    If you have multiple accounts, turn them on one at at time to figure out which one has the corrupt message, i use imap, so used a webmail interface on my PC to look for random messages that could be the problem (in trash, in drafts, sent, etc.) and deleted and purged them, and now MAIL OPENS NORMALLY AGAIN — I haven’t seen it download 25 messages in weeks.

    Seems like the “corrupt photo message” is probably the problem! Or something similar… anyway hope this helps someone else!

  • http://zixmailencryption.com/ zixmail

    i have read this site and there are more good link!

Previous post:

Next post: