Setting up Procmail Filtering for Spam on Postfix/Courier+MySQL Virtual Users

courierpostfixprocmailvirtual-hosting

I've been searching for a resource on how to do this but not having much luck.

I am running a working MTA/MUA that is based on Postfix and Courier with MySQL as a backend for virtual users. I based my system on the following article:

https://help.ubuntu.com/community/PostfixCompleteVirtualMailSystemHowto

It was great up until the empty sections! My SMTP/IMAP setup is working great, and I managed to get SpamAssassin and ClamAV installed as well with some separate documentation I found online.

What I need help with is setting up Postfix to use Procmail as the mailbox_command so that it will work with virtual users. I want to be able to define different Procmail rules for each virtual user separately. I've read the Postfix documentation, and as I understand it the default functionality for mailbox_command will only work for local (non-virtual) users.

Thanks in advance!

UPDATE:

Since this post, I've come to realize that mailbox_command is not tenable. Instead I found a way to do this using transport_maps. Read my own answer below.

Best Answer

Create one global procmailrc, and for each user make a rule like this:

:0
^TOsomeuser@yourdomain.com
| /usr/bin/procmail -m /etc/procmailrcs/someuser

The usual final rule of each file in /etc/procmailrcs/ should then be to pipe the message to deliver(8).

If you have many users and don't want to maintain a file of this nature, then instead consider writing a script that parses the mail headers to figure out which file in /etc/procmailrcs/ is wanted and executes procmail accordingly, and setting that script as your mailbox_command.