The header_checks directive lets Postfix rewrite headers of the mail it processes.
possibly outdated More than two years have passed since publication. The content may no longer hold.
Enabling it
In main.cf:
header_checks = regexp:/etc/postfix/header_check
regexp is one of the supported map types.
Rules in header_check
- Cut the header short before
something.REPLACEreplaces the whole header, so bothsomethingand everything after it disappear:
/(.*)(something)/ REPLACE $1
- Prefix a matched header with
X-and keep the rest:
/^(Received: from somehost)(.*)/ REPLACE X-$1$2
- Drop specific headers:
/^Received: from 127.0.0.1/ IGNORE /^Received: from localhost/ IGNORE
- Collapse a multiline header, keeping the format valid:
/(.*)(..\(This is the line from a multiline header\))(.*)/ REPLACE $1$3
The leading .. is needed to keep a valid header format – otherwise you get a BAD HEADER and the message can be discarded.
_Originally published in January 2014._