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 on oldhost types an address such as "user@oldhost", it goes out with SMTP as "user@oldhost" instead of "u...@oldhost.legacy.org". A machine with postfix (newhost.standard.org) has a different domain (standard.org) from the legacy machine. It acts as MX and relay for the oldhost.legacy.org domain. Relaying in both directions works fine. Only the address rewriting function which I'm trying to add is not working properly. 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 "u...@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.legacy.org If I test with: postmap -q "user@oldhost" pcre:/etc/postfix/canonical.pcre the answer is: u...@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 appends the domain of the postfix host, rewriting the address as u...@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. This seems like a catch-22 situation. I don't want to turn off append_dot_domain or append_at_myorigin because I need that for the local linux machine where postfix is running. If the canonical table rewrites were applied first, then the append_... functions would not apply. So how do I get postfix to apply the canonical table first (or at all)? Michael