PDA

View Full Version : Redirecting spam with procmail


AlArenal
6th November 2007, 16:46
Hi!

I'm trying to get this setup to work:

I use a standard ISPConfig installation and so I use postfix, spamassassin over procmail, etc. I created an email account spam@mydomain.tld and added the following code to my spamassassin.rc.master file. Afterwards I changed my accounts so the config got regenerated and reflected my changes in the user's local .spamassassin.rc . Here's my code snippet:

:0:
* ^TO_.*@mydomain.tld
* !^X-Loop: spam@mydomain.tld
* ^X-Spam-Status: Yes
| formail -A "X-Loop: spam@mydomain.tld" | \
/usr/sbin/sendmail -oi spam@mydomain.tld

This code works, meaning all mail that gets marked as spam by spamassassin also gets redirected to spam@mydomain.tld. However there is one drawback:
The mails in my spam account contain the original mail (as returned by spamassassin) several times attached to itself (maybe some 50 times or so). It looks pretty strange and I don't see why this happens.

Can anyone please turn on the light for me?

P.S.:
It seems the mails get checked by spamassassin over and over again until finally they're to big (>256k) to be handled.

AlArenal
6th November 2007, 17:16
I should have thought about a minute later ;)

It's now clear that with the standard procmail recipe every mail gets scanned by spamassassin first before further evaluation is done. So there's my loop. I'm just curious whether or not it's sufficient to change this...

* < 256000
| /home/admispconfig/ispconfig/tools/spamassassin/usr/bin/spamassassin --prefs-file=/var/www/myweb/user/myuser_spam/.user_prefs

into that:

* < 256000
* !^X-Spam-Status: Yes
| /home/admispconfig/ispconfig/tools/spamassassin/usr/bin/spamassassin --prefs-file=/var/www/myweb/user/myuser_spam/.user_prefs

matiasCU
15th January 2009, 12:09
Hi AlArenal:
Could you tell me how to include the domain name in the file spamassassin.rc.master?
Its posible to use some variable in the spamassassin.rc.master to return the value of the domain to which the user? Eg spam@VARIABLE
I was trying with {DOMAIN}, but apparently not under the environment of users.

Thanks in advance.

AlArenal
15th January 2009, 12:21
Hi matiasCU,

I just hardcoded some passages in customized_templates/spamassassin.rc.master because I didn't want to redirect spam for each and every domains' mail account.

To redirect spam for every account of a domain:

#:0:
* ^TO_.*@domain.tld
* !^X-Loop: spam@webseiter.de
* ^X-Spam-Status: Yes
| formail -A "X-Loop: spam@webseiter.de" | \
/usr/sbin/sendmail -oi spam@webseiter.de


Because you can use regular expressions you have at least some flexibility defining addresses and domains, ...

matiasCU
16th January 2009, 22:54
First of all thanks to Al.
My Requirement:
I needed to redirect spam to an account spam@domain.tld, but also needed to make one copy of the user spam folder, so I did the following:

In /root/ispconfig/isp/conf/spamassassin.rc.master:
Change this lines:
:0fw
* < 256000
| {SPAMASSASSIN_PATH} --prefs-file={PREFS_FILE}

To this:
:0fw
* < 256000
* !^X-Spam-Status: Yes
| {SPAMASSASSIN_PATH} --prefs-file={PREFS_FILE}

And add this lines:
# For copy spam message in user Spam folder
:0 c
* ^X-Spam-Status: Yes
$MAILDIR/.Spam/

# And to forward spam message to spam@domain.tld
:0:
* !^X-Loop: spam@domain.tld
* ^X-Spam-Status: Yes
| formail -A "X-Loop: spam@domain.tld" | \

...and that's all old!

mehulved
17th October 2009, 17:54
Thank you MatiasCU and AlArenal. I was looking for the solution too. Works nicely :)