Symptoms: mail is held or rejected, and the log (/var/log/mail.log) shows an error such as regexp map /etc/postfix/header_checks, line 12: regular expression is bad or bad syntax.
Cause
header_checks is a list of regular-expression rules. One line has a wrong pattern. Postfix refuses to use the file, so every message that needs the check is deferred.
1. Find the line
The log names the file and line number:
grep -i "header_checks" /var/log/mail.log | tail -5
sed -n '12p' /etc/postfix/header_checks # replace 12 with the line number
2. The correct format
Each rule is /pattern/ ACTION. A pattern is enclosed in slashes, and a special character such as $, ., (, ) or + needs a backslash \ in front. For example:
/^Subject:.*(Large US\$ amounts)/ DISCARD
/^Subject:.*invoice/i HOLD
- Put the flags (such as
ifor ignore case) after the closing slash. - Start each rule at the beginning of the line, with a space or tab between the pattern and the action.
- Lines starting with
#are comments.
3. Test it
A regexp table is not compiled, so you do not need postmap to build it. Test the rules instead:
postmap -q "Subject: Large US\$ amounts" regexp:/etc/postfix/header_checks
It prints the action (for example DISCARD) when a rule matches, and an error when the file is invalid. Make sure the table is listed in main.cf as the right type:
postconf header_checks
It should read regexp:/etc/postfix/header_checks (or pcre: for Perl-style patterns, which needs postfix-pcre).
4. Check and reload
postfix check
systemctl reload postfix
postqueue -f
postqueue -f retries the deferred mail now.
Careful with DISCARD
DISCARD throws a message away without telling the sender. While you test a rule, use HOLD or WARN so you can see what it catches and release it later with postsuper -H QUEUEID.
If you cannot find the problem, open a ticket with the log line and the file's contents.