I'm writing a script that takes messages saved in a certain mailbox in Mail (on my Mac), processes them, and then moves them to anothe rmailbox to prevent them from being processed again. I want to run this as an idle handler. (The reason I want to do this instead of using mail rules is that my mail rules to call Applescript have become unreliable in Mountain Lion.)
The problem I am running into is that, even though the UI of Mail.app shows that the message has moved to the othe rmailbox, the scripting interface still thinks it's in the original mailbox. If I quit mail and start it up again, the scripting interface gets back in sync with the UI.
Here's an example script:
setmessageListtoeverymessageofmailbox "Messages to Process" whereread statusisfalse
setmessageListtoeverymessageofmailbox "EPP Messages to Process"
I set up the mailbox "Messages to Process" with two messages. One of them is marked read and the other is unread. Then I run this script. The message marked unread is moved to the other mailbox, but the last line gets both the message that has moved and the one that was left behind. If I run the script again, the first set messageList line still gets the message that is no longer in the "Messages to Process" mailbox.
Is this a known bug? How can I work around this? Is there a less disruptive way to get the scripting interface to sync up with reality than quitting Mail and restarting it?
I hope fixing the Mountain Lion bugs in Mail scripting is a priority, because I'm deeply regretting upgrading to Mountain Lion.