Post.Office & SpamAssassin (Rewrite Subjects and Spam Reports)
Post.Office Tips & Tricks: Index
Tenon added SpamAssassin support to Post.Office in version 3.5.3 (build 720). SpamAssassin works quite nicely once you've set it up and configured but the Post.Office SpamAssassin module has a few drawbacks. One of the most serious shortcomings is that you can't get any header rewrites through the module. The SA-module just reports to Post.Office if a message is spam or not but doesn't allow for the original message to be modified.
This is where my script comes in.
A cron job is executed every hour to scan the local spam-catcher mailbox and then redistributes any found messages to the right user folder.
In order to use this script, you must copy all spams to a local spam-catcher mailbox. This is done by creating a new Post.Office user account on your server with a POP3 mailbox. After you've done that, you should change the SMTP-Filter setting in Post.Office to copy filtered messages to the newly created account.
The script can just rewrite the subject to make it easy to indentify the spam or it can run SpamAssassin again to use the full SpamAssassin report features. This is all done before the script puts the message back into the local user mailbox.
New version: 0.21 - November 29th, 2004 - spamsortnew.sh
The new version has several enhancements. However the configuration wizard and in-depth documentation are not yet available.
This version has these additional features:
- uses the faster spamc client instead of full spamassassin program. This speeds up analysing of messages by a great deal.
- it's possible to use different SpamAssassin settings per user if your server allows users to store SA-settings in MySQL. (documentation for this kind of setup will follow if there's enough interest $$$ ;-))
- lets you remove spam automatically from your local spam-catcher mailbox
- if the spam score of a message is greater than a multiple of the required_hits defined in the SpamAssassin configuration
(e.g. you set the required_hits to 5.0 and the spamsort maximum hits multiplier to 3, then all messages with a score higher than 15 will be removed or quarantined)
- if the message was caught by SpamAssassin because it matched a certain rule
(e.g. remove all spam that got flagged because it was matched by SpamHaus RBL [RCVD_IN_SBL])
- the companion script (dailyspamnew.sh) checks the user's Junk folder and deletes messages older than 30 days. It also provides a daily summary (From: and Subject:) of the messages in the Junk folder. You should run this script once per day through a cron job.
Current version: 0.1 - updated 29th January 2004
- first public release
- added the possibility to scan messages by SpamAssassin again
Here are the features of the script:
- distributes caught messages to the right user folder after rewriting the subject
- possible to include and exclude user accounts just in case you don't want to apply this to all mailboxes
- allows you to run messages through SpamAssassin again to use SA's report writing features
And best of all, there is an online configurator/wizard for the script which allows you to set your preferred configuration without having to wade through code of my shell script.
- MacOS X 10.2.x with Post.Office
- SpamAssassin from the Post.Office distribution
- Local mailbox where you copy spam messages to
- root access on your server
This script has been tested on MacOS X 10.2.x and is currently running a our mail server (MacOS X 10.2.8) without any problems.
Here's a quick installation guide:
- use the online configurator to adapt the script for your system or download the default script
(You won't need to edit the script in a text editor afterwards.)
- copy the spamsort.txt file to the top level of your server
- open your Terminal application
/Applications/Utilities/Terminal.app
- change to the root user by typing the following after
root#
su -
- move spamsort.txt from the top level to the root home directory
mv /spamsort.txt ~/spamsort.sh
- go to the root home directory
cd ~root
- change the file permissions of spamsort.sh to make it executable
chmod 755 spamsort.sh
- change the file ownership of spamsort.sh
chown root:wheel spamsort.sh
- run the spamsort script for the first time manually
./spamsort.sh
This will take some time as it checks all files in your spamcatcher mailbox for a first time. It will also show any errors that could occur. After the first run, the script will only verify the newest files since the last execution.
- Append your list of cron jobs (
/etc/crontab ) to execute the spamsort.sh every hour
echo "0 * * * * root ~root/spamsort.sh > /dev/null 2>&1" >> /etc/crontab
Careful: be sure it says " >> /etc/crontab" as this will append the cron job at the end of the crontab file. If there is just a single > it will overwrite the whole crontab file.
You can also edit your crontab file manually with your favorite command line editor by putting
0 * * * * root ~root/spamsort.sh > /dev/null 2>&1
at the end of that file.
- All done. The script now executes every hour and scans your spamcatcher mailbox for new messages to re-distribute them.
It wasn't all that hard, was it?
Make sure to read the rest of this page as well and if the spamsort system is working for you, please support the development by donating something... :-)
Here's a list of files and folders that are being used by the script. This information is provided just for your information, so you know what is going where.
- The name of the script:
spamscript="/var/root/spamsort.sh"
- The location of Spamassassin:
spamassassin="/usr/bin/spamassassin"
- A file to store temporary messages in:
tmpmessage="/tmp/satmp.txt"
- The Post.Office program directory. It's taken from the Post.Office configuration file but can be changed manually.
programdir=`grep "ProgramDir" /etc/post.office.conf | cut -d "=" -f 2`
usually this is results in programdir="/usr/local/post.office"
- The log file of this spam sort script is written to the standard log directory
spamsortlog="/var/log/spamsort.log"
Current version: 0.1 - updated 29th January 2004
- first public release
- added the possibility to scan messages by SpamAssassin again
Please support the development of these scripts through PayPal. Thank you.
Copyright by Jochen "Joe" Savelberg - © 2003-2004 -- Last Modified: 29th January 2004