Deleting Mail Messages with Applescript - They stay in Inbox?

This seems a little strange. I have an applescript that I run on some messages to train the bayesian spam filter on my IMAP (non-Google) account, and one of the towards the end it uses the Applescript delete command to delete the message:

tell application "Mail"

(* other stuff here *)

set theSelection to selection

set theMessage to item 1 of theSelection


deletetheMessage

end tell

When I then look at the account on another mail client (say, my phone), the messages do appear in the Trash folder, but they are also still in the Inbox, too. It's like Mail only sent a copy command, or forgot to tell the server to remove the message from the Inbox. This is true even if I run a "synchronize" command from mail.


Then, when I quit Mail and restart (or put the computer to sleep overnight), the messages also re-appear in the Inbox there.


I don't see this behavior if I delete the messages personally in Mail, it only occurs with the applescript delete command.


Is there something I'm missing from the script? Or is there some better way to delete a message using IMAP?

iMac (21.5-inch Late 2009), OS X Mavericks (10.9.2)

Posted on May 3, 2014 10:39 AM

Reply
3 replies

May 4, 2014 5:40 AM in response to Drew Reece

Thanks, that got me on the right track. Searched a little more and changed the end to:


tell application "Mail"

(* do stuff *)

set theSelection to selection

set theMessage to item 1 of theSelection

set theAccount to account of mailbox of theMessage

setmailboxoftheMessagetomailbox "Trash" oftheAccount

end tell

And that seems to work.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Deleting Mail Messages with Applescript - They stay in Inbox?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.