How to move spam mails sent to a shared folder automatically to a spam folder

Your rating: None

Concern:
Only spam mails which are sent to a user mailbox are moved to a spam folder per default. Spam mails sent to a shared folder mailbox are tagged as spam by spamassassin but still delivered to the corresponding shared folder mailbox.

Solution:
Replace the smtp line in /etc/postfix/master.cf with:

smtp inet n - n - - smtpd -o content_filter=procmail:spamfilter -o smtpd_sasl_auth_enable=yes

Create the file /etc/procmailrc with the following content:

SENDER=$1
SHIFT=1

:0fw
| /usr/bin/spamc

:0
* ^X-Spam-Flag:.YES
* ^(To|Cc):.*(sharedfolder1|sharedfolder2|sharedfolder3).*$
| /usr/lib/cyrus/bin/deliver -e -r spamfolder -a mailadmin -m spamfolder

:0
| /usr/sbin/sendmail -i -f "$SENDER" -- "$@"

Where (sharedfolder1|sharedfolder2|sharedfolder3) are the names of the shared folders with direct mail delivery and where spamfolder in the /usr/lib/cyrus/bin/deliver line is a usual shared folder just created for spam mails which are sent to the different shared folders on your system.

Open-Xchange | Impressum