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
with
[RT 179497] Internal: blah blah
So drop the hash. Does anyone know the regex to achieve this with postfix header_checks?
See header_checks(5) for examples and http://www.postfix.org/BUILTIN_FILTER_README.html#limitations for additional information.
Modifying the example in the mentioned man page is not that hard:
/etc/postfix/main.cf:
/etc/postfix/header_checks.pcre:
It could probably be done more elegant or shorter, but that's your job now.
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
This instructs postfix to process mails destined for these locations using the
rewriter
transport. Then, in/etc/postfix/master.cf
, you can add: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 defaultheader_checks
file, it's just a custom version only valid for mails passing through therewriter
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.