How to debug an AppleScript intended to be run by a Mail rule?
I created a mailbox on the same imap server and moved some junk mail into it (5 or 6 messages).  I then created my rule that called the script.  I disabled the other rules just to make sure that they were not doing anything weird.

Then select one or more messages in the sample mailbox and do Mail =&gt; Message =&gt; Apply Rules which will send the selected messages through the rules which ends up calling the script.  This is tied to CMD-OPT-L so its possible to cycle from compile and save in the script editor, switch to Mail to run the rules and back to the Script Editor all from the keyboard.