S
stupidnic
Guest
Okay. It has taken me a little bit of time to figure out this process, but I have finally figured out how to do this.
First off, some disclaimers:
DO NOT ATTEMPT IF YOU DON'T KNOW WHAT YOU ARE DOING!
If you mess this up you could potentially stop delivery of messages to your users, so please understand what you are doing before you attempt this.
You must be using at least Plesk 8.1.1. This will NOT work for versions prior to this version.
I tested this all on Plesk 8.1.1, so I can only tell you that it works on that version. I know for a fact that it will NOT work on Plesk 8.0, because Plesk changed how the filtering occurs with spamc from version 8.0 to 8.1 (for the better thankfully).
Now that we have that stuff out of the way, here is how you can filter messages tagged as spam by spamassassin and move them to a folder other than the default POP3/main folder.
Things you are going to need:
Plesk's SpamAssassin module
maildrop
The way this process works right now is that Plesk makes changes to the users .qmail file to call psa-spamc with an argument to dictate if the message should be dropped (reject), or delivered (accept).
We are modifying the accept behavior to change how the messages are delivered. The reject method will still drop the message without delivering the message. The goal here is to work with Plesk rather than replacing what it does.
You are going to need to install maildrop on your server. The filtering script that I am going to provide below is written to use maildrop's filtering methodology.
I am running Debian so I just ran:
apt-get install maildrop
Another server I have is CentOS based and does not include maildrop in yum, so I had to compile it manually. If you have to do this, be sure to note the location of the maildrop binary, as you will need it later.
Once you have maildrop installed, you will need to install the following maildrop script.
You should put this file in /etc/mailfilter and make its owner popuser with group popuser (chown).
Now you need to modify the shell for the user popuser, otherwise the checks, and maildirmake commands will fail to execute properly and mail will not be delivered.
Change:
This line can also end in /bin/false, you just want a valid shell for this user.
To:
Last thing to change is the psa-spamc file itself.
We want to change the section:
To read:
IMPORTANT
Make a backup copy of this file. If you ever upgrade Plesk, it could be overwritten and you will need to make these changes again to get your spam filtering working once more.
Make sure that the path to maildrop is the correct path to maildrop and the same for the grep and wc binaries.
Also make sure that the path to 'test' is correct. The purpose of the 'test' line it so check for the existence of the .Spam folder and to create maildir if it doesn't.
Please let me know if you have any questions and I will attempt to answer them the best that I can.
Good luck.
First off, some disclaimers:
DO NOT ATTEMPT IF YOU DON'T KNOW WHAT YOU ARE DOING!
If you mess this up you could potentially stop delivery of messages to your users, so please understand what you are doing before you attempt this.
You must be using at least Plesk 8.1.1. This will NOT work for versions prior to this version.
I tested this all on Plesk 8.1.1, so I can only tell you that it works on that version. I know for a fact that it will NOT work on Plesk 8.0, because Plesk changed how the filtering occurs with spamc from version 8.0 to 8.1 (for the better thankfully).
Now that we have that stuff out of the way, here is how you can filter messages tagged as spam by spamassassin and move them to a folder other than the default POP3/main folder.
Things you are going to need:
Plesk's SpamAssassin module
maildrop
The way this process works right now is that Plesk makes changes to the users .qmail file to call psa-spamc with an argument to dictate if the message should be dropped (reject), or delivered (accept).
We are modifying the accept behavior to change how the messages are delivered. The reject method will still drop the message without delivering the message. The goal here is to work with Plesk rather than replacing what it does.
You are going to need to install maildrop on your server. The filtering script that I am going to provide below is written to use maildrop's filtering methodology.
I am running Debian so I just ran:
apt-get install maildrop
Another server I have is CentOS based and does not include maildrop in yum, so I had to compile it manually. If you have to do this, be sure to note the location of the maildrop binary, as you will need it later.
Once you have maildrop installed, you will need to install the following maildrop script.
Code:
import HOME
VHOME=$HOME
if ((/^X-Spam-Flag:.*YES/))
{
`/usr/bin/test -d $VHOME/Maildir/.Spam/`
if ( $RETURNCODE == 1 )
{
`/var/qmail/bin/maildirmake $VHOME/Maildir/.Spam/`
}
to "$VHOME/Maildir/.Spam/"
}
#If it isn't Spam or Virus, then deliver normally
to "$HOME/Maildir/"
You should put this file in /etc/mailfilter and make its owner popuser with group popuser (chown).
Now you need to modify the shell for the user popuser, otherwise the checks, and maildirmake commands will fail to execute properly and mail will not be delivered.
Change:
Code:
popuser:x:110:31:POP3 service user:/var/qmail/popuser:/sbin/nologin
To:
Code:
popuser:x:110:31:POP3 service user:/var/qmail/popuser:/bin/bash
Last thing to change is the psa-spamc file itself.
We want to change the section:
Code:
if [ $check -ne 1 -o "$1" != "reject" ]; then
"$QMAIL_LOCAL" -- "$USER" "$HOME" "$LOCAL" "" "" "$HOST" "$SENDER" "$DEFAULT" < "$tmpfile"
else
retval=99
fi
To read:
Code:
if [ $check -ne 1 -o "$1" != "reject" ]; then
FORWARD=`/bin/grep "^&" $HOME/.qmail | /usr/bin/wc -l`
if [ $FORWARD -ne 0 ]; then
"$QMAIL_LOCAL" -- "$USER" "$HOME" "$LOCAL" "" "" "$HOST" "$SENDER" "$DEFAULT" < "$tmpfile"
else
/usr/bin/maildrop /etc/mailfilter < "$tmpfile"
retval=0
fi
else
retval=99
fi
IMPORTANT
Make a backup copy of this file. If you ever upgrade Plesk, it could be overwritten and you will need to make these changes again to get your spam filtering working once more.
Make sure that the path to maildrop is the correct path to maildrop and the same for the grep and wc binaries.
Also make sure that the path to 'test' is correct. The purpose of the 'test' line it so check for the existence of the .Spam folder and to create maildir if it doesn't.
Please let me know if you have any questions and I will attempt to answer them the best that I can.
Good luck.