Postfix Filters and header_checks

kirk kirk at
Mon Aug 15 16:56:21 MDT 2005

Postfix can reroute messages to another recipient using the REDIRECT action 
a pattern in the headers and the body matches.

    REDIRECT test at
Then using the virtual and alias table make pipe to your script

/^(.*)@example\.com$/                emailadmin+$1 at

emailadmin: "| perl /var/email_admin.i $EXTENSION"

$EXTENSION ends up being 'test'

Does this help?

----- Original Message ----- 
From: "Dennis" <devel at>
To: "Provo Linux Users Group Mailing List" <plug at>
Sent: Monday, August 15, 2005 4:18 PM
Subject: Re: Postfix Filters and header_checks

kirk wrote:

>I use amavisd-new and it works just great.
>Also, on another note please be very carefull using /Match Something/
>FILTER ??:??
>I created an endless loop the other day when the message_id of an email was
>caught by a header_check
>I had was checking for /sex/ instead of something like /^Subject: sex/
>However, I use the virtual user table, and the alias table to filter any
>emails that come in ending in
>/^(.*)@emailadmin\.com$/                emailadmin+$1 at
>emailadmin: "| perl /var/email_admin.i $EXTENSION"
>let me know if this is something like what you want and I will be happy to
>explain further.
>- Kirk Cerny
I'm actually not doing it for spam purposes.  I want to process emails
that I send out that bounce back.  I can add a header to the email I
send, and then getting email back I can simply run it through the script
if the header matches and do some work to record the bounced email.

I did get the header_checks to run the script, (foo:bar=filter:dummy)
but it did create an infinite loop like you mentioned.  Another option I
can get to work is to have the script process every email but check for
the header. (I'd rather have postfix check that so I don't have to worry
about it.)  So I'd be interested in learning how you avoid the infinite

Perhaps there is a better solution I'm missing.


>----- Original Message ----- 
>From: "Tyler Strickland" <tyler at>
>To: "Provo Linux Users Group Mailing List" <plug at>
>Sent: Monday, August 15, 2005 3:01 PM
>Subject: Re: Postfix Filters and header_checks
>On 08/15/05 13:57, Dennis wrote:
>>Anybody know how to get a filter to work with postfix?
>>Here is what I want..
>>/Match Something/  FILTER ??:??
>>All the documentation I find for the header_checks just says foo:bar
>>where I put ??:??.  I just want to execute a script with the mail as the
>>input and then have the mail delivered unaltered.  So what is foo:bar
>>supposed to really be?  The docs/man pages say it's
>>transport:destination but I'm having trouble figuring out how to make
>>transport:destination into path/args for my script.
>>Any thoughts?
>As mentioned in another reply, the setup is the same as for
>content_filter.  My setup for content_filter is thus:
>content_filter = amavisd-new:[]:10024
>amavisd-new is foo, the rest is bar.  amavisd-new references an entry in
>your file.  Mine, for example, is:
>amavisd-new     unix    -       -       n       -       2       lmtp
>         -o lmtp_data_done_timeout=1200s
>         -o disable_dns_lookups=yes
>As you can see, postfix passes the message to amavisd-new via LMTP.
>Amavisd-new then scans the message (using clamav) and returns clean
>messages to a smtpd process listening on port 10025 as started by this
> entry:
> inet    n       -       n       -       -       smtpd
>         -o content_filter=
>         -o local_recipient_maps=
>         -o relay_recipient_maps=
>         -o smtpd_restriction_classes=
>         -o smtpd_client_restrictions=
>         -o smtpd_helo_restrictions=
>         -o smtpd_sender_restrictions=
>         -o smtpd_recipient_restrictions=permit_mynetworks,reject
>         -o mynetworks=
>         -o strict_rfc821_envelopes=yes
>That smtp process sends the message on to its final destination, be that
>locally (though your mail delivery agent (MDA)) or externally.
>If you're only concerned about incoming messages, another option you may
>want to look into is sending the message to your filter using your MDA,
>which is probably procmail or maildrop.  They both provide ample
>functionality for passing a message to an external filter.  I can walk
>you through setting up the filter in Maildrop if you like.  I'm sure
>others here have procmail experience they can contribute.
>| This has been a P.L.U.G. mailing. |
>|      Don't Fear the Penguin.      |
>|  IRC: #utah at   |
>| This has been a P.L.U.G. mailing. |
>|      Don't Fear the Penguin.      |
>|  IRC: #utah at   |

| This has been a P.L.U.G. mailing. |
|      Don't Fear the Penguin.      |
|  IRC: #utah at   |

More information about the PLUG mailing list