MacOS – Mail.app AppleScript to process POP3 mails stopped working in Lion

applescriptmacosmail.apppop

I have a Mail.app rule script that worked fine in Mac OS X Snow Leopard. It is simply a script that allows for AND/OR boolean logic combined together to trigger one (rarely two) of the following actions:

  1. Move message to archive folder
  2. Delete email message (move to trash)
  3. Forward the message to someone
  4. Color the message (to signal importance)

You can review the script here. The bulk of the script is made of the boolean conditions I’m looking at (and yes, I know my multiple 'else if's' could have been combined into fewer if statements, but I just found it easier to have each ‘condition’ that I’m looking for in its own if statement).

In Snow Leopard, everything worked fine, but in Lion I get some strange behavior. My Inbox gets tricked/stuck thinking it has emails to download. Basically every message that would have been ‘moved/deleted’ somehow doesn’t get flagged as processed on my POP3 server. So every time I get mail, I see the following under Mail Activity: ‘Incoming Messages… X of Y’ (where Y is the growing number of emails affected by my script), yet nothing new is downloaded.

If I turn my Mail Rule off that runs the script, all emails are re-downloaded again into my Inbox. A few points of note:

  • I’m connecting to POP3 accounts
  • I used to use Growl 1.2.2, but I disabled that on a hunch that it wasn’t compatible with Lion. You’ll still see a sendGrowl function in the script, but you’ll notice that the entire function body is commented out.

Any suggestions or ideas on how to get this working again so I could tame my inbox would be EXTREMELY appreciated.

Best Answer

Judging from your description of the issue, it seems that Lion’s Mail.app has difficulties correctly executing a move AppleScript action on a PO3 server (or maybe just your POP3 server – not having a POP server to test myself, I cannot check). A solution could be to separate the two components of the move operation by replacing the line

move eachMessage to mailbox "Archived/BTR Monitoring Emails"

with

copy eachMessage to mailbox "Archived/BTR Monitoring Emails"
delete eachMessage

in the hope that an express deletion command will fare better. If that doesn’t alleviate the issue (because the deletions suffer from the same issue – I can’t say for sure from your question), you could also try setting the delete status of the message instead of sending it a delete command, i.e.

copy eachMessage to mailbox "Archived/BTR Monitoring Emails"
set deleted status of eachMessage to true

though I’m not entirely sure how that will go down within a POP server (it sounds like something designated for IMAP).

Finally, you could try commenting out the set read status of eachMessage to true lines in the filing and deletion blocks – this should, by rights, not affect the server, as POP3 has no notion of a “read status” (you need IMAP to store that server side), but it might conceivably be an issue if Mail’s AppleScript thinks otherwise. Setting the message status to read can also be achieved within a rule without resorting to AppleScript, so removing this from the script should be a non-issue.