3

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?

1
  • Sorry, we would also want the rewrite to only occur if it is destined for a particular address, so if it is addressed to [email protected] Jul 2, 2010 at 5:07

2 Answers 2

4

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:

header_checks = pcre:/etc/postfix/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.

1

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

[email protected]   rewriter:
[email protected]   rewriter:
.anotherdomain.com  rewriter:

This instructs postfix to process mails destined for these locations using the rewriter transport. Then, in /etc/postfix/master.cf, 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .