C-Command Software Forum

Remote Training Script Gives Error

I’ve had the same remote training script for about a half dozen years:

on run
	my doRemoteTraining()
end run

on perform_mail_action(_info)
	my doRemoteTraining()
end perform_mail_action

on doRemoteTraining()
	tell application "Mail"
		set _mailbox to mailbox "Is Spam" of account "Don"
		repeat with _message in messages of _mailbox
			set _source to _message's source
			tell application "SpamSieve" to add spam message _source
			-- Would like this to go On My Mac, but don't know how
			set _message's mailbox to mailbox "Junk" of account "Don"
		end repeat
	end tell
end doRemoteTraining

I added the doRemoteTraining() and run handlers tonight so I could troubleshoot. I moved the script to my Mountain Lion system after running it for years on Leopard. I’m getting an error on this line:


		set _mailbox to mailbox "Is Spam" of account "Don"

The error is “Mail got an error: Can’t get mailbox “Is Spam” of account “Don”.” I double-checked; the account is correct, the mailbox is correct, and if I loop through the mailbox names in the account I get a hit on “_mailbox is equal to ‘Is Spam’”. If I use your remote training script, Michael, I still get the error. Any ideas?

If you leave off the of account “Don” it will use On My Mac.

You must have modified my script because it works with a mailbox named “TrainSpam” not “Is Spam”. Have you tried using the script as written? I’ve seen cases where Apple Mail’s AppleScript fails if the mailbox name contains a space.

I get the same error with your unmodified script and the mailbox name changed to “TrainSpam”:

error "Mail got an error: Can’t get mailbox \"TrainSpam\" of account \"Don\"." number -1728 from mailbox "TrainSpam" of account "Don"

Is there any possibility that this message might be related?

9/10/12 1:39:33.361 PM Mail[80227]: *** Assertion failure in -[IMAPAccount _IMAPMailboxForMailboxUid:name:createIfNeeded:], /SourceCache/Message/Message-1486/Message/IMAP/IMAPAccount.m:1421
Didn't create IMAPMailbox for (null)
...

Rebuilding the database (removing Envelope Index) didn’t solve either error.

Ah. The IMAP prefix for the inbox was wrong. I found that out when I tried creating a new “TrainSpam” mailbox. Once I fixed that, both errors disappeared.