How to Avoid Duplicate Search Results when using Apple Mail.app with Gmail

I use Gmail’s IMAP feature with my Apple Mac OS’s built in Mail.app program. Mail.app keeps local copies (on all my personal Macs) of all my email messages that I’ve kept (since 1994). It enables me to:

  • Effectively work offline with all my emails (searching, reading and composing), when my computer is not online. That’s sometimes the case when I’m traveling, especially in places where Internet access is unavailable, unreliable, slow, insecure or too expensive.
  • Regularly back up all my saved emails using Apple’s Time Machine. It is also a precaution in case I someday no longer have my Gmail account and/or move to another email service. With email account theft rampant these days, it is important to have up to date backups of all your emails.
  • Send digitally signed and encrypted emails when needed.
  • Compose greeting cards and other visually rich emails with pictures on Mail.app’s stationary.

The Problem:

When you initially set up Mail.app to use Gmail via IMAP, you will observe that when you search your mail using Apple’s built in Spotlight feature, the search results will show duplicate (or more) copies of your email. This is because Gmail’s labels and special views (like “All Mail” or “Starred”) appear as separate IMAP folders in Mail.app. Messages in these seemingly “separate IMAP folders” appear to be duplicates to Mail.app and Spotlight search.

The Solution:

To solve this problem, I suggest showing only essential Gmail special views and labels as IMAP folders to Gmail and then telling Spotlight search to only index the master copies of the messages in Gmail’s “All Mail” folder. To accomplish this, I did the following.

Note: I do the labeling of my messages via the Gmail Web interface and do not need to see the labels applied to messages when I’m using Mail.app. My solution below hides all my custom Gmail labels from Mail.app and that’s fine with me.

In Gmail (via the Web interface)

Go to “Settings > Labs” and activate “Advanced IMAP Controls“. After enabling it, go to “Settings > Labels” and uncheck “Show in IMAPfor each custom Gmail label you have created. Also uncheck it for “Starred” since Mail.app shows to do flags in messages in other folders.

Leave “Show in IMAPchecked yes for “Inbox“, “Sent Mail“, “Drafts“, “All Mail” and “Trash” since these are system folders and Apple Mail.app should be configured to use them. Also leave it checked yes for a label folder called “Apple Mail To Do” which is an Apple Mail system folder.

On your Macs

Go to “System Preferences > Spotlight > Privacy“, exclude the following folders from appearing in search results. Where it says username@imap.gmail.com below, use your Gmail account name.

~/Library/Mail/IMAP-username@imap.gmail.com/INBOX.imapmbox

~/Library/Mail/IMAP-username@imap.gmail.com/[Gmail]/Sent Mail.imapmbox

Also, if you are displaying your starred folder via IMAP, exclude:

~/Library/Mail/IMAP-username@imap.gmail.com/[Gmail]/Starred.imapmbox

Now when you search messages in your Mac’s Mail.app, only results from your Gmail All Mail folder will appear.


Posted

in

by

Comments

8 responses to “How to Avoid Duplicate Search Results when using Apple Mail.app with Gmail”

  1. Marc V.

    Thanks – this is very useful. Maybe you can give me some more tips for synchronizing mail.app with gmail.
    I was on a POP mail account until 3 months ago, when I "migrated" to Gmail Imap. I have about 4GB of archived messages which are managed with MailStewardLite. (I am just under the 15.000 message limit.)

    Is there somewhere a good concise description on how to switch from POP to IMAP. I had about 50 mail folders to keep everything organized – old habits die hard. With the good search possibilities in mail now, this does not make any sense any longer so I try to follow Merlyn Mann's "Inbox to Zero" advice and really keep mail organization to a minimum and use search to find stuff.

    There are however some "hickups" for the unexperienced ; i.e. How can you replicate the "Archived" tag in Gmail on mail.app ? This is just one of the nagging details I cannot get my head around.

  2. Thanks for the tip! I was looking for this solution, because I wanted some achive folders not to be displayed in my mail searches. Thanks!

  3. Rob C

    Mark V: It's easy to get Apple Mail to dump a mailbox out as an mbox file, I had excellent results using http://imap-upload.sourceforge.net/ to move mbox files to Gmail.

  4. Kevin Forey

    You are awesome. Thanks a ton.

  5. Mikael

    I can't select the imapmbox files in the final step as they are greyed out. Is there another way to not get their contents in the search results? (Mail 3.6 in OS X 10.5.8)

  6. This worked brilliantly. Thank you!

  7. Frédéric M

    Opposite question:
    How to search IMAP emails using spotlight ?

  8. Frédéric M

    Opposite question:
    How to search IMAP emails using spotlight ?

Related Articles

%d bloggers like this: