-
-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Hi, I am trying to replicate a Postfix setup where we have certain internal send-only users. Mail sent from those users should be rewritten to match the main address of the real user. For example, the sender of mail from usera-sendonly@example.com should become usera@example.com. After that, we need to create a copy to be sent to the main user.
I got it kind of working with the following trusted Sieve script in the data stage:
require ["variables", "regex", "envelope", "editheader", "copy"];
if address :regex "from" "(.+)-sendonly@example.com" {
set "main_username" "${1}";
set "main_email" "${main_username}@example.com";
deleteheader "From";
addheader "From" "${main_email}";
set "envelope.from" "${main_email}";
redirect :copy "${1}@example.com";
}
I might be missing something here, but Sieve behaves kind of strangely. This rewrites the envelope and headers properly, but no redirect is generated.
Removing set "envelope.from" "${main_email}"; will generate the correctly rewritten headers, but the mail to the original recipient will have unmodified headers.
Setting the envelope rewrite and hardcoding another user redirect like redirect :copy "userc@example.com"; will once again generate a correctly rewritten redirect mail, but the original recipient will have no modified headers.
For reference, here is the Postfix config I tried to replicate:
# main.cf
sender_canonical_maps = pcre:/etc/postfix/sender_canonical_pcre
smtp_header_checks = regexp:/etc/postfix/header_checks
sender_bcc_maps = pcre:/etc/postfix/sender_bcc_pcre
# canonical_maps_pcre
/^(.+)-sendonly@domain$/ ${1}@domain
# header_checks
/^From:.*@domain/ PREPEND X-sendonly: true
# sender_bcc_pcre
/^(.+)@domain$/ ${1}@domain