0

Setup

  • postfix forwards all mails to an archive@domain user via always_bcc,

  • postfix saves all the RCPT TO in X-Envelope-To headers to perserve the bcc recipients,

  • postfix deletes X-Envelope-To for smtp transfers out for privacy reasons,

  • postfix delivers messages to dovecot via lmtp.

  • dovecot uses a sieve script to flush the X-Envelope-To for all users except archive@domain.

Problem

There is one X-Envelope-To for each RCPT TO initially. So I would like the sieve script to add a single Bcc header concatenating several X-Envelope-To values.

require "fileinto";
require "imap4flags";
require ["editheader", "envelope"];
require "regex";
require ["variables","mime","foreverypart"];


if envelope :is "to" "archive@domain" {
   concat = """"";
   foreverypart {
        if header :regex "X-Envelope-To" "(.*)" {
        concat = ${concat}  "${1}";
        }
   }
   addheader "Bcc" "${1}";

} else {
   deleteheader "X-Envelope-To";
}

Which does not work...

Any easy way to do that in sieve ? Or no other way than an external script ? Or perhaps postfix could concatenate all that but that means a milter ?

Thanks in advance

  • foreverypart is for looping over MIME parts, but you are looking for multiple headers in the main message, right? – anx Sep 21 '21 at 12:17
  • yes, exactly: I am trying to iterate over the headers; I thought perhaps there was a way to use the same function but does not seem so. – user3450564 Sep 21 '21 at 19:53
  • https://wiki2.dovecot.org/Pigeonhole/Sieve/Plugins/Extprograms: external sieve script may be the simplest with a simple bash script ? – user3450564 Sep 22 '21 at 01:54
  • Does this answer your question? [Postfix archive preserving Bcc with X-Envelope-To - cleanup confidential X-Envelope-To with Lmtp](https://serverfault.com/questions/1077995/postfix-archive-preserving-bcc-with-x-envelope-to-cleanup-confidential-x-envel) – Michael Hampton Sep 24 '21 at 15:40
  • Yes, I put the link to my own post as answer. thanks – user3450564 Sep 25 '21 at 16:10

1 Answers1

0

See other post. One needs an external sieve script in Bash. See proposal in:

Postfix archive preserving Bcc with X-Envelope-To - cleanup confidential X-Envelope-To with Lmtp