This is more a curiosity than a real need, but I was wondering why I can't
modify the "From" header when sending mails between local users.

It works perfectly when sending mail out (smtp_header_checks).
"sender_canonical_maps" with "local_header_rewrite_clients =
permit_mynetworks, permit_sasl_authenticated" works (though it only edits
the address, not the 'name' in the From)

Just in case something was interfering I reused the same file as with
smtp_header_checks and removed other options.
# postconf 'smtp_header_checks = ' 'sender_canonical_maps = '
'virtual_alias_maps = ' 'local_header_rewrite_clients =
permit_inet_interfaces'
# postconf 'header_checks = pcre:/etc/postfix/smtp_header_checks'
# cat /etc/postfix/smtp_header_checks
/^Received:/                    IGNORE
/^From: .*root/       REPLACE   From: "postmaster" <use...@mydomain.net>
/^Subject: hello/     REPLACE   Subject: bye
# postfix reload
# echo a | mail -s hello user01

Result: "Received" header is removed, Subject is changed, but From is
unchanged...
I do realize that to implement this properly I would probably have define a
second cleanup service that applies to the pickup, submission and smtps
services, but as I said, this is more of a curiosity/obsession at this
point.

Thanks in advance.

postfix version: 2.10.1
cleanup -v log:
postfix/cleanup[5793]: name_mask: all
postfix/cleanup[5793]: inet_addr_local: configured 2 IPv4 addresses
postfix/cleanup[5793]: inet_addr_local: configured 2 IPv6 addresses
postfix/cleanup[5793]: process generation: 606 (606)
postfix/cleanup[5793]: name_mask: envelope_sender
postfix/cleanup[5793]: name_mask: envelope_recipient
postfix/cleanup[5793]: name_mask: header_sender
postfix/cleanup[5793]: name_mask: header_recipient
postfix/cleanup[5793]: name_mask: envelope_sender
postfix/cleanup[5793]: name_mask: header_sender
postfix/cleanup[5793]: name_mask: envelope_recipient
postfix/cleanup[5793]: name_mask: header_recipient
postfix/cleanup[5793]: dict_open: pcre:/etc/postfix/smtp_header_checks
postfix/cleanup[5793]: name_mask: envelope_sender
postfix/cleanup[5793]: name_mask: header_sender
postfix/cleanup[5793]: name_mask: header_recipient
postfix/cleanup[5793]: match_string: fast_flush_domains ~? debug_peer_list
postfix/cleanup[5793]: match_string: fast_flush_domains ~?
fast_flush_domains
postfix/cleanup[5793]: name_mask: canonical
postfix/cleanup[5793]: name_mask: virtual
postfix/cleanup[5793]: connection established
postfix/cleanup[5793]: master_notify: status 0
postfix/cleanup[5793]: mail_flow_get: 1 1
postfix/cleanup[5793]: open incoming/288FE67379
postfix/cleanup[5793]: cleanup_open: open incoming/288FE67379
postfix/cleanup[5793]: send attr queue_id = 288FE67379
postfix/cleanup[5793]: cleanup socket: wanted attribute: flags
postfix/cleanup[5793]: input attribute name: flags
postfix/cleanup[5793]: input attribute value: 115
postfix/cleanup[5793]: cleanup socket: wanted attribute: (list terminator)
postfix/cleanup[5793]: input attribute name: (end)
postfix/cleanup[5793]: cleanup flags = enable_bad_mail_bounce
enable_header_body_filter enable_automatic_bcc enable_address_mapping
enable_milters
postfix/cleanup[5793]: initial envelope T 1557637132 929471
postfix/cleanup[5793]: initial envelope A rewrite_context=local
postfix/cleanup[5793]: initial envelope F root
postfix/cleanup[5793]: initial envelope S root
postfix/cleanup[5793]: connect to subsystem private/rewrite
postfix/cleanup[5793]: send attr request = rewrite
postfix/cleanup[5793]: send attr rule = local
postfix/cleanup[5793]: send attr address = root
postfix/cleanup[5793]: private/rewrite socket: wanted attribute: flags
postfix/cleanup[5793]: input attribute name: flags
postfix/cleanup[5793]: input attribute value: 0
postfix/cleanup[5793]: private/rewrite socket: wanted attribute: address
postfix/cleanup[5793]: input attribute name: address
postfix/cleanup[5793]: input attribute value: r...@mydomain.net
postfix/cleanup[5793]: private/rewrite socket: wanted attribute: (list
terminator)
postfix/cleanup[5793]: input attribute name: (end)
postfix/cleanup[5793]: rewrite_clnt: local: root -> r...@mydomain.net
postfix/cleanup[5793]: initial envelope R user01
postfix/cleanup[5793]: send attr request = rewrite
postfix/cleanup[5793]: send attr rule = local
postfix/cleanup[5793]: send attr address = user01
postfix/cleanup[5793]: private/rewrite socket: wanted attribute: flags
postfix/cleanup[5793]: input attribute name: flags
postfix/cleanup[5793]: input attribute value: 0
postfix/cleanup[5793]: private/rewrite socket: wanted attribute: address
postfix/cleanup[5793]: input attribute name: address
postfix/cleanup[5793]: input attribute value: use...@mydomain.net
postfix/cleanup[5793]: private/rewrite socket: wanted attribute: (list
terminator)
postfix/cleanup[5793]: input attribute name: (end)
postfix/cleanup[5793]: rewrite_clnt: local: user01 -> use...@mydomain.net
postfix/cleanup[5793]: been_here: ?0?user01?use...@mydomain.net: 0
postfix/cleanup[5793]: initial envelope M
postfix/cleanup[5793]: cleanup_header_callback: 'Received: by
mail.mydomain.net (Postfix, from userid 0)??id 288FE67379; Sun, 12 May 2019
01:58:52 -0300 (-03)'
postfix/cleanup[5793]: dict_pcre_lookup: /etc/postfix/smtp_header_checks:
Received: by mail.mydomain.net (Postfix, from userid 0)??id 288FE67379;
Sun, 12 May 2019 01:58:52 -0300 (-03)
postfix/cleanup[5793]: maps_find: header_checks:
pcre:/etc/postfix/smtp_header_checks(0,lock): Received: by mail.mydomain.net
(Postfix, from userid 0)??id 288FE67379; Sun, 12 May 2019 01:58:52 -0300
(-03) = IGNORE
postfix/cleanup[5793]: cleanup_header_callback: 'Date: Sun, 12 May 2019
01:58:52 -0300'
postfix/cleanup[5793]: dict_pcre_lookup: /etc/postfix/smtp_header_checks:
Date: Sun, 12 May 2019 01:58:52 -0300
postfix/cleanup[5793]: maps_find: header_checks: Date: Sun, 12 May 2019
01:58:52 -0300: not found
postfix/cleanup[5793]: cleanup_header_callback: 'To: user01'
postfix/cleanup[5793]: dict_pcre_lookup: /etc/postfix/smtp_header_checks:
To: user01
postfix/cleanup[5793]: maps_find: header_checks: To: user01: not found
postfix/cleanup[5793]: rewrite_recip: To
postfix/cleanup[5793]: rewrite_clnt: cached: local: user01 ->
use...@mydomain.net
postfix/cleanup[5793]: cleanup_header_callback: 'Subject: hello'
postfix/cleanup[5793]: dict_pcre_lookup: /etc/postfix/smtp_header_checks:
Subject: hello
postfix/cleanup[5793]: maps_find: header_checks:
pcre:/etc/postfix/smtp_header_checks(0,lock): Subject: hello = REPLACE
Subject: bye
postfix/cleanup[5793]: 288FE67379: replace: header Subject: hello from
local; from=<r...@mydomain.net> to=<use...@mydomain.net>: Subject: bye
postfix/cleanup[5793]: cleanup_header_callback: 'User-Agent: Heirloom mailx
12.5 7/5/10'
postfix/cleanup[5793]: dict_pcre_lookup: /etc/postfix/smtp_header_checks:
User-Agent: Heirloom mailx 12.5 7/5/10
postfix/cleanup[5793]: maps_find: header_checks: User-Agent: Heirloom mailx
12.5 7/5/10: not found
postfix/cleanup[5793]: cleanup_header_callback: 'MIME-Version: 1.0'
postfix/cleanup[5793]: dict_pcre_lookup: /etc/postfix/smtp_header_checks:
MIME-Version: 1.0
postfix/cleanup[5793]: maps_find: mime_header_checks: MIME-Version: 1.0:
not found
postfix/cleanup[5793]: header_token: text / plain
postfix/cleanup[5793]: cleanup_header_callback: 'Content-Type: text/plain;
charset=us-ascii'
postfix/cleanup[5793]: dict_pcre_lookup: /etc/postfix/smtp_header_checks:
Content-Type: text/plain; charset=us-ascii
postfix/cleanup[5793]: maps_find: mime_header_checks: Content-Type:
text/plain; charset=us-ascii: not found
postfix/cleanup[5793]: header_token: 7bit
postfix/cleanup[5793]: cleanup_header_callback: 'Content-Transfer-Encoding:
7bit'
postfix/cleanup[5793]: dict_pcre_lookup: /etc/postfix/smtp_header_checks:
Content-Transfer-Encoding: 7bit
postfix/cleanup[5793]: maps_find: mime_header_checks:
Content-Transfer-Encoding: 7bit: not found
postfix/cleanup[5793]: 288FE67379: message-id=<
20190512045853.288fe67...@mail.mydomain.net>
postfix/cleanup[5793]: extracted envelope E
postfix/cleanup[5793]: cleanup_flush: status 0
postfix/cleanup[5793]: send attr status = 0
postfix/cleanup[5793]: send attr reason =
postfix/cleanup[5793]: master_notify: status 1
postfix/cleanup[5793]: connection closed
postfix/cleanup[5793]: rewrite stream disconnect

Reply via email to