Postfix Header_Checks Replace Multiple Occurrences Inside References Header

Postfix Header_Checks Replace Multiple Occurrences Inside References Header

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 Answer

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

Demo

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.