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

mail_icon

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?).

mail icon - HighTechDad™

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:

search bar mail app - HighTechDad™

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: [paypal-donation reference=”Mail.app vaccum”]

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

3 Responses

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

  2. 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!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Other articles of interest

Global Product Review Disclosure

Disclosure: This is a global disclosure for product review articles on HighTechDad. It does not apply to Automobile reviews and there are other exceptions. Therefore, it may or may not be applicable to this particular article. I may have a material connection because I may have received a sample of a product for consideration in preparing to review the product and write this or other content. I was/am not expected to return the item after my review period. All opinions within this and other articles are my own and are typically not subject to the editorial review from any 3rd party. Also, some of the links in the post above may be “affiliate” or “advertising” links. These may be automatically created or placed by me manually. This means if you click on the link and purchase the item (sometimes but not necessarily the product or service being reviewed), I will receive a small affiliate or advertising commission. More information can be found on my About page.

About HighTechDad

Michael Sheehan (“HighTechDad”) is an avid technologist, writer, journalist, content marketer, blogger, tech influencer, social media pundit, loving husband and father of 3 beautiful girls living in the San Francisco Bay Area. This site covers technology, consumer electronics, Parent Tech, SmartHomes, cloud computing, gadgets, software, hardware, parenting “hacks,” and other tips & tricks.

Recent Articles

Explore Categories