On Fri, Jun 17, 2022 at 01:14:25PM -0600, Austin Witmer wrote:

> I posted this problem on the dovecot mailing list, and they
> recommended that I use sender_bcc_maps in postfix to bcc messages to
> myself and then use a sieve script to place them in the sent folder.
> 
> I got this working now but the trouble is that it is putting five
> copies of the same email in my sent folder. Does anybody have any
> ideas on why this might be happening?

You have a multi-stage delivery pipeline, with approximately:

On Fri, Jun 17, 2022 at 09:28:43PM -0600, Austin Witmer wrote:

> Jun 18 03:15:40 mail postfix/submission/smtpd[21926]: connect from 
> 97-123-96-141.albq.qwest.net[97.123.96.141]
> Jun 18 03:15:42 mail postfix/submission/smtpd[21926]: 4E16C17A09B: 
> client=97-123-96-141.albq.qwest.net[97.123.96.141], sasl_method=PLAIN, 
> sasl_username=j...@appalachianmeats.com
> Jun 18 03:15:42 mail postfix/cleanup[21933]: 4E16C17A09B: 
> message-id=<047b66f1-3332-acc4-a681-13a4cea8a...@mydomain.com>

    cleanup(8) adds a BCC recipient

> Jun 18 03:15:42 mail opendkim[863]: 4E16C17A09B: DKIM-Signature field added 
> (s=default, d=mydomain.com)

    DKIM milter adds signature to original message on submission

> Jun 18 03:15:42 mail postfix/qmgr[2968]: 4E16C17A09B: 
> from=<u...@mydomain.com>, size=557, nrcpt=2 (queue active)

    Two recipients seen by qmgr(8).

> Jun 18 03:15:44 mail postfix/pipe[21934]: 4E16C17A09B: 
> to=<recipi...@anotherdomain.com>, relay=gpgit-pipe, delay=2.1, 
> delays=0.31/0.01/0/1.8, dsn=2.0.0, status=sent (delivered via gpgit-pipe 
> service)
> Jun 18 03:15:44 mail postfix/pipe[21935]: 4E16C17A09B: 
> to=<u...@mydomain.com>, relay=gpgit-pipe, delay=2.1, delays=0.31/0.02/0/1.8, 
> dsn=2.0.0, status=sent (delivered via gpgit-pipe service)
> Jun 18 03:15:44 mail postfix/qmgr[2968]: 4E16C17A09B: removed

    Delivered separately! to "gpgit-pipe", because content_filter
    definition lacks an explicit "nexthop".

    Change the content_filter to "gpgit-pipe:local" if the filter can
    handle multiple recipients.  Otherwise, delay the BCC to after the
    filter by setting "receive_override_options=no_address_mappings" in
    the submission "smtpd".

> Jun 18 03:15:44 mail postfix/pickup[21737]: 532FF17A09B: uid=1001 
> from=<u...@mydomain.com>
> Jun 18 03:15:44 mail postfix/cleanup[21952]: 532FF17A09B: 
> message-id=<047b66f1-3332-acc4-a681-13a4cea8a...@mydomain.com>
> Jun 18 03:15:44 mail opendkim[863]: 532FF17A09B: DKIM-Signature field added 
> (s=default, d=mydomain.com)
> Jun 18 03:15:44 mail postfix/qmgr[2968]: 532FF17A09B: 
> from=<u...@mydomain.com>, size=1527, nrcpt=2 (queue active)
> Jun 18 03:15:44 mail postfix/smtp[21953]: 532FF17A09B: 
> to=<recipi...@anotherdomain.com>, relay=127.0.0.1[127.0.0.1]:10024, 
> delay=1.9, delays=1.7/0.04/0/0.14, dsn=2.0.0, status=sent (250 2.0.0 from 
> MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 8094B17A0A2)
> Jun 18 03:15:44 mail postfix/smtp[21953]: 532FF17A09B: 
> to=<u...@mydomain.com>, relay=127.0.0.1[127.0.0.1]:10024, delay=1.9, 
> delays=1.7/0.04/0/0.14, dsn=2.0.0, status=sent (250 2.0.0 from 
> MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 8094B17A0A2)
> Jun 18 03:15:44 mail postfix/qmgr[2968]: 532FF17A09B: removed

> Jun 18 03:15:44 mail postfix/pickup[21737]: 62D6A17A0A0: uid=1001 
> from=<u...@mydomain.com>
> Jun 18 03:15:44 mail postfix/cleanup[21952]: 62D6A17A0A0: 
> message-id=<047b66f1-3332-acc4-a681-13a4cea8a...@mydomain.com>
> Jun 18 03:15:44 mail opendkim[863]: 62D6A17A0A0: DKIM-Signature field added 
> (s=default, d=mydomain.com)
> Jun 18 03:15:44 mail postfix/qmgr[2968]: 62D6A17A0A0: 
> from=<u...@mydomain.com>, size=1535, nrcpt=2 (queue active)
> Jun 18 03:15:44 mail postfix/smtp[21956]: 62D6A17A0A0: 
> to=<u...@mydomain.com>, relay=127.0.0.1[127.0.0.1]:10024, delay=2, 
> delays=1.7/0.02/0/0.18, dsn=2.0.0, status=sent (250 2.0.0 from 
> MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 9B45817A09B)
> Jun 18 03:15:44 mail postfix/smtp[21956]: 62D6A17A0A0: 
> to=<u...@mydomain.com>, relay=127.0.0.1[127.0.0.1]:10024, delay=2, 
> delays=1.7/0.02/0/0.18, dsn=2.0.0, status=sent (250 2.0.0 from 
> MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 9B45817A09B)
> Jun 18 03:15:44 mail amavis[19779]: (19779-09) Passed CLEAN {RelayedInbound}, 
> [127.0.0.1] <u...@mydomain.com> -> <u...@mydomain.com>,<u...@mydomain.com>, 
> Message-ID: <047b66f1-3332-acc4-a681-13a4cea8a...@mydomain.com>, mail_id: 
> h4sjymJW2jCC, Hits: -, size: 2047, queued_as: 9B45817A09B, 
> dkim_sd=default:mydomain.com, 170 ms
> Jun 18 03:15:44 mail postfix/qmgr[2968]: 62D6A17A0A0: removed

The two "gpgit-pipe" scripts resubmit each copy of the message via
sendmail(1).  The BCC address is added to both again, and both are
DKIM signed again.  This time, there's a content_filter rerouting
the message into amavis, which does not "split the envelope":

> Jun 18 03:15:44 mail postfix/smtpd[21957]: 8094B17A0A2: 
> client=localhost[127.0.0.1]
> Jun 18 03:15:44 mail postfix/cleanup[21954]: 8094B17A0A2: 
> message-id=<047b66f1-3332-acc4-a681-13a4cea8a...@mydomain.com>
> Jun 18 03:15:44 mail postfix/qmgr[2968]: 8094B17A0A2: 
> from=<u...@mydomain.com>, size=2430, nrcpt=3 (queue active)
> Jun 18 03:15:44 mail postfix/smtpd[21957]: disconnect from 
> localhost[127.0.0.1] ehlo=1 mail=1 rcpt=2 data=1 quit=1 commands=6

> Jun 18 03:15:44 mail postfix/smtpd[21957]: 9B45817A09B: 
> client=localhost[127.0.0.1]
> Jun 18 03:15:44 mail postfix/cleanup[21952]: 9B45817A09B: 
> message-id=<047b66f1-3332-acc4-a681-13a4cea8a...@mydomain.com>
> Jun 18 03:15:44 mail postfix/qmgr[2968]: 9B45817A09B: 
> from=<u...@mydomain.com>, size=2643, nrcpt=3 (queue active)
> Jun 18 03:15:44 mail postfix/smtpd[21957]: disconnect from 
> localhost[127.0.0.1] ehlo=1 mail=1 rcpt=2 data=1 quit=1 commands=6

Each after amavis cleanup adds a BCC again, (ending up with 3
recipients).  Now the original recipient is present once, and
five recipients are the BCC recipient.

> Jun 18 03:15:44 mail postfix/lmtp[21963]: 8094B17A0A2: 
> to=<u...@mydomain.com>, relay=mail.mydomain.com[private/dovecot-lmtp], 
> delay=0.22, delays=0.02/0.05/0.1/0.05, dsn=2.0.0, status=sent (250 2.0.0 
> <u...@mydomain.com> S/9pKWBDrWJqVQAANmah8A Saved)
> Jun 18 03:15:44 mail postfix/lmtp[21963]: 9B45817A09B: 
> to=<u...@mydomain.com>, relay=mail.mydomain.com[private/dovecot-lmtp], 
> delay=0.3, delays=0.01/0.1/0.03/0.16, dsn=2.0.0, status=sent (250 2.0.0 
> <u...@mydomain.com> oEmDLmBDrWJqVQAANmah8A Saved)
> Jun 18 03:15:44 mail postfix/lmtp[21965]: 8094B17A0A2: 
> to=<u...@mydomain.com>, relay=mail.mydomain.com[private/dovecot-lmtp], 
> delay=0.42, delays=0.02/0.14/0.09/0.17, dsn=2.0.0, status=sent (250 2.0.0 
> <u...@mydomain.com> KCCGLmBDrWLOVQAANmah8A Saved)
> Jun 18 03:15:44 mail postfix/lmtp[21965]: 9B45817A09B: 
> to=<u...@mydomain.com>, relay=mail.mydomain.com[private/dovecot-lmtp], 
> delay=0.36, delays=0.01/0.29/0.03/0.03, dsn=2.0.0, status=sent (250 2.0.0 
> <u...@mydomain.com> T0JmOWBDrWLQVQAANmah8A Saved)
> Jun 18 03:15:45 mail postfix/lmtp[21963]: 9B45817A09B: 
> to=<u...@mydomain.com>, relay=mail.mydomain.com[private/dovecot-lmtp], 
> conn_use=2, delay=0.37, delays=0.01/0.3/0/0.05, dsn=2.0.0, status=sent (250 
> 2.0.0 <u...@mydomain.com> INy2OGBDrWJqVQAANmah8A Saved)
> Jun 18 03:15:45 mail postfix/smtp[21913]: 8094B17A0A2: 
> to=<recipi...@anotherdomain.com>, 
> relay=filter.anotherdomain.com[216.24.56.70]:25, delay=0.82, 
> delays=0.02/0/0.55/0.25, dsn=2.0.0, status=sent (250 Ok: queued as 
> 4E14D2E40052)
> Jun 18 03:15:45 mail postfix/qmgr[2968]: 8094B17A0A2: removed

The above is exactly what is expected.

- You'll need to disable "sender_bcc" in all but one of the delivery stages
  via "receive_override_options".

- You should try to avoid splitting the envelope for different
  content_filter recipients Of the same message, by using
  filters that can handle multiple recipients, and transport
  one input multi-recipient message to one output multi-recipient
  message.

  Otherwise, delay BCC until after all such filters.

- You can get more recipient deduplication via
  "enable_original_recipient = no", see the docs for
  corner-case caveats.

--
    Viktor.

Reply via email to