Skip to content

Instantly share code, notes, and snippets.

@joey-coleman
Last active January 7, 2018 20:40
Show Gist options
  • Save joey-coleman/9446995 to your computer and use it in GitHub Desktop.
Save joey-coleman/9446995 to your computer and use it in GitHub Desktop.
Spam training on mavericks server
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>ca.granitedragon.pre-salearn</string>
<key>Program</key>
<string>/usr/local/bin/move-retrain.sh</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/move-retrain.sh</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>2</integer>
<key>Minute</key>
<integer>00</integer>
</dict>
</dict>
</plist>
#!/bin/bash
SERVERADMIN="/Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin"
MAILBASE=`$SERVERADMIN settings mail:imap:partition-default | sed -e 's/.*"\([^"]*\)"/\1/'`
USERS=`ls $MAILBASE/users | grep -v junkmail`
TARGET=$MAILBASE/users/junkmail/cur
for user in $USERS ; do
SOURCE=$MAILBASE/users/$user/.Retrain/cur
if [ "`ls $SOURCE`" ] ; then
mv $SOURCE/* $TARGET
fi
done

background

OS X 10.9.2, Server.app 3.0.3

So, Apple wants users to redirect (not forward!) mail to junkmail@ and notjunkmail@ to retrain the spam filter. I think that sucks --- this is not a reasonable way to do things in my opinion.

Anyway, the mechanism seems to be via the launch daemon configured at

/Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.apple.salearn.plist

which, in turn, runs

/Applications/Server.app/Contents/ServerRoot/usr/libexec/spamassassin/sa_learn.pl

and outputs to /Library/Logs/Mail/junkmail.log

config

  • Create an account with the username junkmail
  • Create an account named notjunkmail too, otherwise the sa_learn.pl script to exit
  • Add move-retrain.sh to /usr/local/bin
  • Add ca.granitedragon.pre-salearn.plist to /Library/LaunchDaemons
  • Then do launchctl load /Library/LaunchDaemons/ca.granitedragon.pre-salearn.plist
  • Profit? (Check the log in the morning.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment