Using your AppleScript drone to train

1 Using a modified version of your AppleScript drone to train messages put in the three iCloud mail boxes that I created “Train Good”, “Train Spam” and “Train Trash”. No other computer has SpamSieve or Apple Filtering turned on. This way I can move a message on another computer to one of those folders and have the drone train it.
2. I’m having an issue with “Train Trash”. I want Spamsieve to train the message so that it always go to the Trash Mailbox. My script isn’t working and I’m hoping you can tell me a better way or tell me what I’m dong wrong. Also SpamSieve appears to get errors in the log when running the drone.

Here is the Apple Script snippet. When I run it the last debug statement I see is “set color”.

display dialog "TrainTrash"
		set _messages to my messagesFromMailbox("TrainTrash", _account)
		set _mailbox to mailbox "Trash" of _account
		repeat with _message in _messages
			display dialog "next message in account"
			set _source to my sourceFromMessage(_message)
			display dialog "after set _source"
			tell application "SpamSieve" to add spam message _source
			display dialog "after SpamSieve to add spam message"
			set _message's junk mail status to true
			display dialog "set _message's junk status to true"
			if pColorSpamMessages then
				set _message's background color to blue
			end if
			display dialog "set color"
			if pFlagSpamMessages then
				set _message's flag index to 99
			end if
			display dialog "set flag"
			if pMarkGoodMessagesUnread then
				set _message's read status to false
			end if
			display dialog "set read status"
			display dialog "moveMesssage"
			my moveMessage(_message, _mailbox, true)
		end repeat

Here is the log right after I run the drone but don’t know if it is important,

root@server ~ # log show --predicate '(process == "SpamSieve")' --start "2024-02-24 12:45:00"
Filtering the log data using "process == "SpamSieve""
Skipping info and debug messages, pass --info and/or --debug to include.
Timestamp                       Thread     Type        Activity             PID    TTL
2024-02-24 12:46:47.473579-0600 0x566993   Default     0x0                  71207  0    SpamSieve: (Security) [] CSSM Exception: -2147415792 CSSMERR_CSP_INVALID_KEY
2024-02-24 12:46:47.474625-0600 0x566993   Default     0x0                  71207  0    SpamSieve: (Security) [] CSSM Exception: -2147415792 CSSMERR_CSP_INVALID_KEY
2024-02-24 12:47:39.657423-0600 0x566993   Default     0x0                  71207  0    SpamSieve: (Security) [] CSSM Exception: -2147415792 CSSMERR_CSP_INVALID_KEY
2024-02-24 12:47:39.658662-0600 0x566993   Default     0x0                  71207  0    SpamSieve: (Security) [] CSSM Exception: -2147415792 CSSMERR_CSP_INVALID_KEY
Log      - Default:          4, Info:                0, Debug:             0, Error:          0, Fault:          0

Well I see that I’m using the wrong thing for _score. The issue is the flag. I’ll turn that back off, it is not what I thought it was.

Should I set the COLOR to Blue and _score to 99 before or after calling “tell application “SpamSieve” to add spam message _source”?

Thanks Michael.


How is this different from training the message as spam?

I don’t think 99 is a valid flag index. Maybe that is making Mail throw an error or get into an invalid state.

I don’t think this means anything.

The score is the output from when you ask SpamSieve to classify a message. You can’t set it.

You can set the color whenever you want.

Hey Michael. Thank’s for getting in touch. There are some messages I never really want to see which can go directly to the Trash Mailbox. I get hundreds and hundreds of messages in my Spam mailbox and some I at least want to look at maybe, but the large majority are from political, investment, or sales mail bots sent over and over and over again. I don’t want to have to deal with them as I go through the spam mailbox. So I thought that if there was some way I could train them as trash, then they would eventually end up in Trash and not in Spam.

Yes I misunderstood the flag index. I had had the boolean set to “false” so it never got executed. Today I changed it to true and that caused my problems which the script not running. Put it back to false. Right now every time I get one of these messages either in INBOX or SPAM I put it in TrainTrash. Eventually, some start ending up in the trash, but there are some that seem to get through over and over. I was looking for a way to tell SpamSieve that this message should be blue, or have a score of 99 and hopefully other messages of that type will eventually end up in trash.

So I have put a Message in Train Trash usually from the Spam mailbox. I want to be able to have Spamsieve know that this message should have a high (99) score next time it sees something like it. I tried to do this with the “Train Trash” snippet enclosed in the forum post. May not be the best way.


Thanks Michael. I’m looking for a way to tell Spamsieve to train this message and messages like it with a high score so they will end up in the trash. Maybe the simplest solution would be to just add the sender’s address to the Blacklist if I put it in TrainTrash. I was just trying to avoid that.



Regular training as spam will add the sender to the blocklist, so that future messages from that sender will go to the trash if you have Move it to the Trash if the spam score is at least checked. I don’t think there is any benefit to modifying the drone script.

Thanks Michael. I finally figured that out. SpamSieve does an amazing job of keeping my inbox manageable. And the script does empty some of the Spam Mailbox to Trash.

I did have another thought. That if Apple Mail has a script directive to block an address I could add that to drone. I know it can be done manually.


That’s what I thought when I added “Train Trash”. But I also found your "Apple Mail - Block Sender” script which may help make the messages more spammy so that they eventually end up in the trash after landing in Spam mailbox.

Thanks again.


I don’t think that part of Mail is scriptable. I don’t recommend using Mail’s blocked message filter because it overrides Mail extensions. This means that SpamSieve won’t be able to protect you from Mail deleting a good message, and also it’s hard to know when to train SpamSieve if Mail is deleting some messages that it incorrectly thought were good.

That script is discussed more here. It’s intended for messages that SpamSieve did classify correctly but where you want to block the sender in the future. You could add that functionality to the remote training script, though I think this is a very niche use case that most people don’t need, and it will cause problems if you don’t properly use it.

Yes Michael, Ithink that is exactly what I’m trying to do. If I put somethng in “Train Trash” I never want to see emails from or like that. I was hopping that if I kept classifing an email from a sender as SPAM over and over by putting into “Train Trash” over and over that it would eventually be scored as 99 but some kept coming back. This isn’t exactly what I envisioned, but should work to delete all of these bot messsages. I get hundreds a day, many duplicates, usually about trying to sell me something, so even more likely false flag or false news to try to convince me that something that is not true is actually true. I don’ want to waste my time looking through them over and over. Basically all I want in Spam are emails from companies that I done business with in the past or sometimes there are potentially interesting articles that I may or may not want to read. So I go through Spam one email at a time looking at title. Then I delete all SPAM. SpamSieve is keeping my INBOX clean of things I don’t want to necessarily see. Now I’m trying to figure out a way to keep my SPAM box manageable. I think hopefully that your “Apple Mail - Block Sender” script will do that. Thanks so much for the attention that you have provided me. I’ve used and enjoyed SpamSieve for years.


That sounds like what you want. Just to be extra clear: this is only for messages that SpamSieve did catch as spam. If the message is in your inbox, you should use Train as Spam instead.

Before I run this I train as spam. Not many message come from inbox but occasionally. Basically I added the processing part of this script to my current TrainTrash script which is processing one message at a time.

Thanks for the heads up!


Then there is no reason to run it because Train as Spam already blocks the sender.