Fix new message counts with Gmail IMAP and Mail

Apr 10, '08 07:30:00AM

Contributed by: wesg

IMAP with Gmail is an excellent solution for keeping email coordinated on multiple platforms. Unfortunately, the way that Mail.app and Gmail communicate means that there are a number of annoyances. My largest complaint is that the unread mail count is always double the real number. This disappears once the message is read in the inbox, but until then, it is misleading.

My solution was to write a quick AppleScript that marks the unread message in the folder [Gmail]/All Mail as read immediately on retrieval:

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
    end repeat
  end if
end tell
Be sure to change Gmail IMAP to the name of your Google account. If you're unsure of the official name, add get accounts in the tell application section to find the official name. While this is far from an elegant solution, it could help until Apple and Google coordinate their efforts. If you have any suggestions to make this script more efficient, please share!

[robg adds: Although it's not stated in the hint submission, I believe the last step is to assign this script to run as a rule on all inbound Gmail messages...]

Comments (13)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20080405191647566