Remove unread count from Gmail IMAP
If you’re still using a POP email account, you should have a look at other providers. Gmail recently began offering IMAP service for its clients, and it is a much better way of organizing your email.
IMAP is different from POP email because it keeps all messages and attachments on the central Gmail servers. This means that regardless of how or where you download and view messages – whether on your computer, iPod, iPhone or other device – you see the same inbox, with the same unread/read messages. This is different than POP because POP requires you to download all new messages onto your computer, which makes retrieval from different places awkward.
I use Apple’s Mail.app for all of my email duties, and its integration with IMAP accounts presents some unique challenges. One of the things it does is create a complete deposit for all the messages ever sent with your account in a special folder. In itself not a bad thing, in fact it can be quite handy, but it means that you now have duplicate copies of most of your messages, and twice as many unread messages.
Until Apple and Google coordinate their efforts and make Gmail as seamless on the Mac as they have with the iPod/iPhone, there are a few things you can do to make the experience easier. One of the ways is to use this hint from MacOSXHints.com. It gets rid of the duplicate mailboxes in Gmail. Next, you have to find a way to get rid of the double mail count. To do this, I came up with a simple Applescript that is evaluated whenever there is a new message.
tell application "Mail"
set unreadBox to mailbox "[Gmail]/All Mail" of account "Gmail IMAP"
set unreadCount to unread count of unreadBox
if unreadCount is not 0 then
repeat unreadCount times
set unreadMail to first message of unreadBox whose read status is false
set read status of unreadMail to true
This tells Mail to mark every message in the All Mail folder as read, thereby reducing the number of unread messages to their correct value. Be sure to change the account name to your correct account. To find this out, open Mail’s preferences and use the account nickname you’ve set up.
To use this script in Mail, you’ll need to open Script Editor (/Applications/Applescript/Script Editor) and save this text as a script in some place you’ll remember. Then open Mail’s preferences, and create a new rule that is evaluated at each incoming message. Find the script file, and you should avoid the excess messages.
Update: If you don’t want to write and save the script yourself, you can easily download the script directly.