0

I`m setting up Postfix to edit the headers dependent on the reciever. This is done through header_checks(http://www.postfix.org/header_checks.5.html)

The logic is as follows: If the e-mail is sent to "erik@sorgaard.net" then we copy the From field and an paste it to the Reply-To field, the From field is also set to "erik@sorgaard.net".

I have no experience with regexp but through some searching I was able to come up with the following:

if /^To: (erik@sorgaard.net)\s.*$/
/^From: (.+@.+)\s.*$/ PREPEND Reply-To:$1
/^From: (.+@.+)\s.*$/ REPLACE From: erik@sorgaard.net
endif

This does not work. I'm not sure what's wrong with the syntax, but any help would be very appreciated.

Regards Erik

  • did you want the regex to match `id's`? – Avinash Raj Jun 23 '14 at 11:30
  • No, I´m not aware of any ids here, just pure e-mail addresses represented as strings. This syntax: (.+@.+) is merely to match the actual e-mail address and not any tailing string that contains name. – Erik Sørgaard Jun 23 '14 at 12:05
  • The [documentation](http://www.postfix.org/header_checks.5.html) says `if /pattern/flags endif` If the input string matches `/pattern/`, then match that input string against the patterns between if and endif. While your pattern is `To` header, how can you match `From` headers inside `if`? – clement Jun 24 '14 at 12:51
  • Well the `if` statement is only really dependent on the `To` field. Aslong as that matches the script should edit the `From` and `Reply-To` fields. I know my code might be very borked, but Im totally lost here and would appreciate any help. – Erik Sørgaard Jun 24 '14 at 13:14

2 Answers2

3

It looks like the accepted answer might mislead.

If you fight with if-endif in header_checks you should keep in mind the following:

If  the  input  string  matches /pattern/, then match that input
string against the patterns between if and endif.  The if..endif
can nest

from http://www.postfix.org/header_checks.5.html

Pay attention to "then match that input string". This means you can't operate any header inside the if/endif block but the one you use in if-statement.

Tobias K.
  • 2,997
  • 2
  • 12
  • 29
scythiang
  • 146
  • 1
  • 4
1

The problem is that the header_checks are applied only one time for each email line, so the seconf "From" line (line 3) is skipped.

Fale
  • 404
  • 1
  • 4
  • 9