Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

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 example@whatever.com –  bobinabottle Jul 2 '10 at 5:07

2 Answers 2

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.

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

example1@test.com   rewriter:
example2@test.com   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.

share|improve this answer

Your Answer

 
discard

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.