I’m having difficulty getting the canonical_maps function to work as needed to repair some incorrect addresses from a legacy client. Here’s the situation and what I’ve tried so far:
Legacy client (oldhost.legacy.org) does not append its domain (legacy.org) to addresses in the envelope or the message when sending them via SMTP. So, if the user types an address such as “user@oldhost”, the legacy clients sends it out with SMTP as “user@oldhost” instead of “user@oldhost.legacy.org”.
A machine with postfix has a different domain (standard.org) from the legacy machine. It also acts as MX and relay for the oldhost.legacy.org domain.
When messages from the legacy client arrive at the postfix machine with addresses such as “user@oldhost” (missing .legacy.org), I’d like to rewrite those to read “user@oldhost.legacy.org” . It’s my understanding that the canonical_maps function is intended for this purpose.
In /etc/postfix/canonical.pcre I have:
/^(.*)@oldhost&/ $1@oldhost.legacy.org
If I test with: postmap –q “user@oldhost” pcre:/etc/postfix/canonical.pcre
the answer is:
user@oldhost.legacy.org. Perfect.
In /etc/postfix/main.cf I have
canonical_maps = pcre:/etc/postfix/canonical.pcre
Then, on the legacy host, I send a message such as:
To:
user@someotherhost.domain
Cc: user@oldhost
The message arrives at the postfix machine, but the CC line is not rewritten.
The documentation for canonical_maps says that in order for the headers to be rewritten, the client needs to either match the local_header_rewrite_clients or else the remote_header_rewrite_domain must be non-null. I tried both but neither produces the output that I need. Here's what I found:
If I set local_header_rewrite_clients = static:all or permit_mynetworks or some other option that would cause a match of the legacy client, then the append_dot_domain option takes over and rewrites the address as
user@oldhost.standard.org. The canonical table is apparently ignored.
If I instead leave local_header_rewrite_clients at its default (which does not match the legacy client) and turn on remote_header_rewrite_domain = invalid.domain, then the address is rewritten as
user@oldhost.invalid.domain and, once again, the canonical table is apparently ignored.
So the documentation for the canonical table is correct in that rewriting only occurs if the local_header_rewrite_clients matches the client or if remote_header_rewrite_domain is set. And the rewrites are indeed occurring. But the rewriting that takes place completely ignores the canonical table.
So how do I get Postfix to apply the append_dot_domain and append_at_myorigin only to the local and apply the canonical table to other clients or, at least apply the canonical table first?