Preventing duplicate Gmail IMAP messages in Mail.app (Mac OS X)

For an email client, I use Mac OS X's Mail.app, which I'm perfectly happy with (in conjunction with [Mail Act-On](http://www.indev.ca/MailActOn.html), which I find to be indispensable). To access my various email accounts, I use both POP and IMAP; each offers me something the other does not. When I am on the road in places with poor internet infrastructure, I find that POP is more friendly; when network connections are abruptly terminated, I am at least able to keep the messages I have already downloaded. I find IMAP's overhead to be too much for very slow connections.

When I moved to using Gmail as my primary email aggregator, I decided that synchronization was more important, so I moved (back) to IMAP. However, I use Mail.app as my primary mail client, and it is notoriously terrible at IMAP.[^1] Luckily, Gmail has a feature that allows configuration of what "folders" (labels, in Gmail) show up for IMAP clients. It can be found in *Settings->Labels*, assuming you have turned IMAP access on. You also need to turn on *Advanced IMAP Controls*, which can be found in "Settings->Labs".

[^1]: IMAP folder subscriptions are hidden in the *Account Info* pop-up window in Mail.app, which is very hard to find. You can get to it by clicking on your account's inbox in the Mailboxes sidebar, clicking on the gear at the bottom of the sidebar, and selecting "Get Account Info" at the bottom of the pop-up menu. Alternatively, you can hit Command-I after selecting your account's inbox in the sidebar.

When Google introduced [Priority Inbox](http://mail.google.com/mail/help/priority-inbox.html), I turned it on because it looked like a great feature. Unfortunately, turning on Priority Inbox caused duplicated message problems in Mail.app. Gmail's "Priority Inbox" is a "System label," along with Buzz, Starred, Important, and other labels. All of these can be accessed as IMAP folders. But if you turn Priority Inbox on and set it to show Important and Unread messages (a reasonable thing to do), every new message that comes in will suddenly exist (in IMAP) in both your Inbox and in your Priority Inbox.

My standard workflow involves moving messages from my Gmail inbox to a local mailbox on my computer (so I can keep a copy of my email archive outside of Google). When a message is moved from Gmail's IMAP inbox, Gmail automatically archives it. But with messages starting to appear in multiple IMAP folders, Mail.app was actually downloading message more than once, and I would frequently end up moving multiple versions of messages to my local archive.

All of this gets worse if you use filters to set messages as *Important* or *Starred*. And if you access *All Mail* via an IMAP folder, you are screwed: have you ever seen Mail.app try to download 100,000 messages via IMAP? It's not pretty.

The solution is easy: in Gmail, go to *Settings->Labels* and uncheck *Priority Inbox*. While you're there, you might want to uncheck everything else except for *Drafts*.[^2]

[^2]: I used to also access my *Spam* folder via IMAP. I did this originally so I could use a keyboard shortcut to move messages into the spam folder from Mail.app (Google learns from this). Ultimately, it felt too silly to download all of my spam, so I unchecked it.

If you've set up Mail.app properly, local drafts to be saved in Gmail's Drafts folder (and will be available via the web client). There is no need to save sent mail to Gmail's Sent Mail folder because Gmail automatically does this for you if you send it through their SMTP server.