Mail: Refresh Issue

Mail Refresh Issue:

After moving or deleting messages from a Mail box or folder, AppleScript will continue to act as if the message is still in that location. There is not a command that will refresh the contents of the box or folder so you are left with these choices:

  1. Quit/Relaunch - A quit and relaunch will refresh the contents of the mailboxes. However, if you have a complex solution that is constantly checking multiple boxes for mail, constantly quitting and relaunching feels kind of clunky. [This appears to work in every OS to date]

  2. Send New Mail - Sending (or receiving) a new piece of mail to the mail account in question seems to refresh the inbox. However, then you will need to remove and ignore the “refreshing” email message and this doesn’t appear to help if you are deleting mail from a folder. [This should work in every OS to date]

  3. Access the Window - This solution has been posted on an AppleScript mailing list (Jan 2006). Rather than telling Mail to count messages of an account, you tell mail to count the messages of the message viewer. According to the posts, this seemed to work in previous versions. However, tests indicate that it does not solve the problem in 10.5.

  4. Erase Deleted Messages - telling Mail to perform this step appears to be the best way to refresh a Mail box or folder. In 10.5, this menu has a key command so it is easily accessed with a UI Scripting “keystroke” command and does appear to refresh the message counts in boxes and folders. Previous versions (10.4 and 10.3) will need to be accessed with a UI Scripting “menu” command and may also solve the problem. Using this step may require a change in the way your script functions. For example, if you are processing emails and then want to store them in a folder, you will need to copy them into the folder and then delete them from the original box or folder.

Mail also has a “synchronize account” and “rebuild” menu items which at first appear to refresh an inbox, but they did not seem to work reliably.

Hopefully, Apple will add a way to simply refresh a box or folder or will make this happen automatically when deleting or moving a message.