example for ver 0.4 couple bigger changes from 0.1-0.3 versions - check the script header for more --- * maildir format only * utf-8 as default in whole script (sendmail message, DB queries) * TODO: possibility of combining the filter rules * TODO: maybe HTML format e-mail with sendmail, maybe e-mails from external files You should always use base e-mail address for the filter rules. I mean, if you have mail account 'test@mydomain.com' and for example, two aliases: root@mydomain.com -> test@mydomain.com and postmaster@mydomain.com -> test@mydomain.com, script in this case will check if the base address exists, so when you want to make some fe. autorespond for the 'postmaster@mydomain.com', you should add the filter rule for the 'test@mydomain.com' address (don't worry sender address in the e-mail header will be 'postmaster@mydomain.com') --- postfix configuration: 'main.cf' (somewhere) ssqllda_destination_recipient_limit = 1 virtual_transport = ssqllda 'master.cf' (on the bottom) ssqllda unix - n n - - pipe flags=q user=vmails:vmails argv=/usr/sbin/ssqllda.pl ${user} ${domain} ${sender} ${original_recipient} 'user=' - use your virtual user 'argv=' - put script to your favorite directory When you are ready with config files, reload postfix and do simple test by sending e-mail. If all is ok, you should see something like this in 'mail.log': [..] Dec 1 13:43:49 tweety postfix/cleanup[4971]: CDE8DC839A: message-id=<201112011343.49675.jane@doe.org> Dec 1 13:43:49 tweety postfix/qmgr[4637]: CDE8DC839A: from=, size=1253, nrcpt=1 (queue active) Dec 1 13:43:49 tweety postfix/smtpd[4965]: disconnect from doe.org[6.6.6.6] Dec 1 13:43:50 tweety postfix/pipe[4972]: CDE8DC839A: to=, relay=ssqllda, delay=1.2, delays=1.1/0/0/0.15, dsn=2.0.0, status=sent (delivered via ssqllda service) Dec 1 13:43:50 tweety postfix/qmgr[4637]: CDE8DC839A: removed [..] --- database name, for example: 'postifx_lda' (name it as you want) 'main' table for the script: mysql> describe main; +---------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | email | varchar(128) | NO | | NULL | | | order | int(11) | NO | UNI | NULL | | | type | varchar(16) | NO | | NULL | | | header | varchar(256) | NO | | NULL | | | pattern | varchar(256) | NO | | NULL | | | action | varchar(16) | NO | | NULL | | | message | varchar(512) | NO | | NULL | | | subject | varchar(256) | NO | | NULL | | | maildir | varchar(256) | NO | | NULL | | +---------+--------------+------+-----+---------+----------------+ 10 rows in set (0.00 sec) Order field should be uniq and the whole table should be in UTF-8. Order of the filter rules is important (loop & ORDER by `order` ASC). Remember to escape any special characters in pattern field - script won't do it for you. Test your regexps before use in this script. fields: 'id' - id with auto increment option 'email' - for which e-mail/account filter rule should work 'order' - order for filter rules (inserted manually) 'type' - matching source: 'sender' (e-mail address of the sender), 'subject' (incomming e-mail subject), 'header' (header of the e-mail message) 'header' - name of the header field, for example: 'X-Bogosity' 'pattern' - regex pattern for the filter rule (PCRE - $_ =~ m/$sql_pattern/) 'action' - what to do if pattern match: 'copy' (copy e-mail to other directory/maildir), 'respond' (send message via sendmail to the sender), 'nosave' (do not save e-mail in the default maildir) 'message' - plain text message for the 'respond' action 'subject' - plain text subject for the 'respond' action 'maildir' - directory name for the 'copy' action - - - examples: When the our e-mail address doesn't exist in the 'main' table, script tries to deliver e-mail to the default maildir directory ('new' as default). Oke, let's make some simple rules. Make a copy of e-mail and put in some other directory, sender's address matches the pattern: mysql> select * from `main`; +----+----------------+-------+--------+--------+---------+--------+---------+---------+-------------------------------------+ | id | email | order | type | header | pattern | action | message | subject | maildir | +----+----------------+-------+--------+--------+---------+--------+---------+---------+-------------------------------------+ | 7 | some@mailss.pl | 1 | sender | | @ | copy | | | /home/mail/mailss.pl/other_user/new | +----+----------------+-------+--------+--------+---------+--------+---------+---------+-------------------------------------+ 1 row in set (0.00 sec) Text respond without saving e-mail in maildir, sender's address matches the pattern: mysql> select * from `main`; +----+----------------+-------+--------+--------+---------+---------+---------+---------+---------+ | id | email | order | type | header | pattern | action | message | subject | maildir | +----+----------------+-------+--------+--------+---------+---------+---------+---------+---------+ | 2 | some@mailss.pl | 1 | sender | | @ | respond | Hello! | Topic. | | +----+----------------+-------+--------+--------+---------+---------+---------+---------+---------+ 1 row in set (0.00 sec) Copy e-mail message to the 'trash' when header pattern matches (example e-mail header field: X-Bogosity: Unsure, tests=bogofilter, spamicity=0.499999, version=1.1.7) mysql> select * from `main`; +----+----------------+-------+--------+------------+---------+---------+---------+---------+---------------------------------+ | id | email | order | type | header | pattern | action | message | subject | maildir | +----+----------------+-------+--------+------------+---+---------+---------+---------+---------------------------------------+ | 9 | some@mailss.pl | 1 | header | X-Bogosity | unsure | copy | | | /home/mail/mailss.pl/some/trash | +----+----------------+-------+--------+--------+---+---------+---------+---------+---------+---------------------------------+ 1 row in set (0.00 sec) (unsure - ;D) Text respond without saving e-mail in the default maildir. mysql> select * from `main`; +----+----------------+-------+--------+--------+---------+---------+---------+---------+---------+ | id | email | order | type | header | pattern | action | message | subject | maildir | +----+----------------+-------+--------+--------+---------+---------+---------+---------+---------+ | 2 | some@mailss.pl | 1 | sender | | @ | respond | Hello! | Topic. | | +----+----------------+-------+--------+--------+---------+---------+---------+---------+---------+ | 3 | some@mailss.pl | 2 | sender | | @ | nosave | | | | +----+----------------+-------+--------+--------+---------+---------+---------+---------+---------+ 2 rows in set (0.00 sec) There are many, many more combinations, use your brain ;-)