Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have a number of external systems reading from our emails, and some are tripping over others. Basically what I need to do is replace an email subject like:

[RT #179497] Internal: blah blah


[RT 179497] Internal: blah blah

So drop the hash. Does anyone know the regex to achieve this with postfix header_checks?

share|improve this question
Sorry, we would also want the rewrite to only occur if it is destined for a particular address, so if it is addressed to – bobinabottle Jul 2 '10 at 5:07

See header_checks(5) for examples and for additional information.

Modifying the example in the mentioned man page is not that hard:


header_checks = pcre:/etc/postfix/header_checks.pcre


/^Subject: \[RT #(\d)\] Internal: (.+)$/    REPLACE Subject: [RT $1] Internal: $2

It could probably be done more elegant or shorter, but that's your job now.

share|improve this answer

Adding to the answer by @joschi (and I know this is late but someone else might find this information helpful): You indicated that you only want to rewrite headers on messages for certain e-mail addresses. This is a bit tricky:

You need to set up a separate transport so that you can specify different manipulation for messages using this transport:

default location: /etc/postfix/transport   rewriter:   rewriter:  rewriter:

This instructs postfix to process mails destined for these locations using the rewriter transport. Then, in /etc/postfix/, you can add:

rewriter     unix  -       -       -       -       -       smtp
  -o smtp_header_checks=regexp:/etc/postfix/rewrite_headers

And finally, you specify what sort of rewriting you want to actually do in the /etc/postfix/rewrite_headers file. It has the same syntax as the default header_checks file, it's just a custom version only valid for mails passing through the rewriter transport.

Note, this will probably not work if you have any sort of content filter active (for example Amavis), though in my case I was running a different manipulation.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.