Testing postfix header_checks with postmap -q

This post makes some assumptions, for example that you use Postfix, Ubuntu, and regexp format for your header_checks, etc. but I find that testing new rules isn’t all that well documented and I always forget how to do this.

Testing header checks with postmap -q:

For a single line:

postmap -q "From: my spammer" regexp:/etc/postfix/header_checks

If you match a “REJECT” line you should get “REJECT” as a response. If you get nothing, your rule isn’t working. You can make the switch -vq (has to be in that order) to get verbose logging, but I don’t find that really helpful. It either works or it doesn’t and you’re not going to get any special regexp help from postmap.

If you’ve saved spam message headers to a file (ex: /tmp/spam.txt), do this:

postmap -q - regexp:/etc/postfix/header_checks < /tmp/spam.txt

That second dash is important or it won't work.