Postfix header_checks replace multiple occurrences inside References header

1.1k Views Asked by At

In postfix header_checks can be used to replace any header. This works for example perfectly for the Message-Id header.

Example:

/Message-Id:\s+<(.*?)@domain-a.com>/ REPLACE Message-Id: <[email protected]>

Any mail which is processed by postfix will be checked for the Header:

Message-Id: <[email protected]>

and gets replaced with:

Message-Id: <[email protected]>

How does this work with References Header?

Example Header:

References: <[email protected]> <[email protected]> <[email protected]>

Goal:

Replace any (1 - n) occurrence of domain-a.com with domain-b.com in this References header.

Try 1:

#/References:\s+<(.*?)@domain-a.com>/ REPLACE References: <[email protected]>

(works only with first occurence)

Try 2:

#/<.*?@(domain-a.com)>/ REPLACE domain-b.com

Does not work because header_checks need a valid Header name for the REPLACE command.

Can this replace achived with postfix native header_checks?

1

There are 1 best solutions below

1
Michail On

You can use (^References:|\G(?!\A)).*?@\Kdomain-a\.com with substitution domain-b.com

Demo