1

I need to modify the "From:" header line in incoming e-mail messages only if "Message-Id:" starts with a defined string. So in main.cf I put:

header_checks = pcre:/etc/postfix/header_checks

and header_checks file contains:

if /^Message-Id: <footext.+/
/^From: (.*)@johndoe.com/ REPLACE From: ${1}@ext.johndoe.com
endif

It doesn't work, the condition does not take. What am I missing?

Gabriele
  • 341
  • 1
  • 4
  • 14
  • Finally I managed to do the same kind of job by a simply Python script: https://unix.stackexchange.com/questions/389323/forward-email-but-change-the-from-address – Sunry Apr 05 '20 at 12:16

2 Answers2

2

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

if /pattern/flags

   endif  Match the input string against the patterns between
          if  and endif, if and only if ----> the same <----- input string
          also matches /pattern/. 

you can not use an if/endif block to match a different header.

Gryphius
  • 2,720
  • 1
  • 19
  • 19
  • So it seems header_checks is no good to my needs, isn't it? Can you suggest a way to have a conditional replace among header fields (matching a different header line)? Thanks in advance for any help you will offer. – Gabriele Apr 14 '13 at 07:11
  • I'm not sure there is a simple way to do this with postfix internal features. For this kind of stuff, I usually attach a content filter like [FuGlu](http://www.fuglu.org) (disclaimer: written by me) – Gryphius Apr 15 '13 at 07:43
  • Couldn't find the quote in the link anymore. So it seems this syntax would work in the newer versions of postfix?!? – t7tran Jun 04 '20 at 06:07
  • No, the restriction is the same like before, things have only been rephrased: `[...]then match **that input string** against the patterns between if and endif.` – Thorsten Schöning Oct 12 '21 at 15:42
  • There's an additional section in the docs making that clear as well: `Many people overlook the main limitations of header and body_checks rules.` `These rules operate on one logical message header or one body line at a time. A decision made for one line is not carried over to the next line.` – Thorsten Schöning Oct 12 '21 at 15:58
0

I came across this post and thought to update since I had a similar issue: I took a different approach using postfix pipe as suggested in some of these resources:

and just because I ran into the issue of loops:

SysadminB
  • 71
  • 1
  • 6