Remote Training Spam and Gmail

I had some difficulty getting the remote training of spam and good emails to work when using my IMAP Gmail account. In step 5 of section 5.5.7 of the manual, Setting up a Spam Filtering Drone, the mailbox “TrainSpam” should instead be “[Gmail]/TrainSpam” in order to work with the Gmail label/folder mailbox. Correspondingly, the mailbox “TrainGood” should be “[Gmail]/TrainGood”.

Here’s the scripts that I got to work:

RemoteSpamTraining.scpt:

on perform_mail_action(info)
tell application “Mail”
set _mailbox to mailbox “[Gmail]/TrainSpam” of account “AccountName”
repeat with _message in messages of _mailbox
set _source to _message’s source
tell application “SpamSieve” to add spam message _source
set _message’s mailbox to mailbox “[Gmail]/Spam” of account “AccountName”
end repeat
end tell
end perform_mail_action

RemoteGoodTraining.scpt:

on perform_mail_action(info)
tell application “Mail”
set _mailbox to mailbox “[Gmail]/TrainGood” of account “AccountName”
repeat with _message in messages of _mailbox
set _source to _message’s source
tell application “SpamSieve” to add good message _source
set _message’s mailbox to mailbox “INBOX” of account “AccountName”
end repeat
end tell
end perform_mail_action

Note that the “INBOX” mailbox is not prefaced with “[Gmail]/”.

Hope this helps someone else using Gmail.

Thanks for the tip. Alternatively, Gmail users may want to set the IMAP Path Prefix to “[Gmail]” in Mail’s Accounts preferences.

Struggling
This is taking a long time and a lot of trial and error to get set up properly for drone operation. But I’m super excited about having an actual, working, effective SPAM filter once it’s tweaked and working.

So I discovered the Remote Training script wouldn’t run unless it was before the SpamSieve rules… so tip, put the Remote Training rule on top. Works for me. Unless I’m missing something?

I also am having trouble with all my TrainSpam mails going to the respective Junk folders except Gmail, whose junk mail stubbornly stays in the TrainSpam folder. Is OP suggesting the mailbox be named “Spam” but referred to as “[Gmail]/TrainGood”? or that the “Spam” mailbox be renamed to “[Gmail]/TrainGood”?

Michael, I’m also not finding an option in the Mail Accounts preference pane "set the IMAP Path Prefix to “[Gmail]” as you suggest. I’m using OS X Sierra (10.12.5).

Thanks in advance!

Yes, that’s what the instructions recommend in Step 4. Otherwise the remote training script will only run when you receive a new good message.

You can check the Console for errors to see why that is.

No.

In Sierra, it’s under Accounts > Server Settings > Advanced IMAP Settings > IMAP Path Prefix.

Amazed
Michael, your responsiveness and patience are amazing!

There it was, plain as day. I skipped right over that. Sorry.

In Sierra, it’s under Accounts > Server Settings > Advanced IMAP Settings > IMAP Path Prefix.

Oops, I didn’t see the IMAP Path Prefix because I was going straight to Accounts, not through Preferences. But now that I’m looking, this is what I find:

  1. Under the “Server Settings” tab it only shows “Outgoing Mail Account”, and if I choose Google there are no editable parameters. If I select “Edit SMTP Server List” it only shows my non-Google servers.

  2. Under the “Mailbox Behaviors” tab it does not allow you to add prefixes, but it does appear to be set up correctly. I have the “Junk” mailbox already set to “[Gmail]/Spam”. Do I need to fix this somewhere else? or do I edit my AppleScript to reflect that?

Thanks again!

It looks like for Gmail accounts Mail doesn’t show that option but that it is auto-configured the right way. So you should be able to use the standard AppleScript.

Success!

SUCCESS!!! I edited the AppleScript to change the default behavior (return {}) to:

on spamMailboxNamesByAccount()
– You can specify pairs here, e.g. {{“Work Account”, “Junk”}, {“Personal Account”, “Spam”}}
– to have different spam mailbox names for each account. If an account is not specified,
– it defaults to pSpamMailboxName.
return {{“Work”, “Spam”}, {“Personal”, “Spam”}, {“Google”, “[Gmail]/Spam”}}
end spamMailboxNamesByAccount

Even though my Gmail “Description” is Google, Apple Mail calls it “Gmail,” only worked when I did it this way.

Thanks a bunch, Michael, you’re amazing!

SpamSieve is making me hopeful again about sanity in my inbox. For a few months, I’d been feeling increasingly angry/frustrated/powerless every time I see that 2/3 of my emails are SPAM (and on top of that, 2/3 of my non-SPAM are things I don’t feel like reading, industry newsletters, etc.!).

Should I just set people I actually email as VIPs and just not expect good emails in my regular inbox?

Yes, I think that name comes from the server.

That can work, or personally I use rules to move the less important messages to separate mailboxes.

I will look further into OS X Mail’s rules to see how they can help me.

The drone setup is humming along very nicely! Thanks again!!!