This is actually a follow-up question to this post: Postfix aliases and duplicate e-mails, how to fix?
(I don't have enough reputation to comment on that post.)
I have setup my Postfix + Dovecot as the first answer suggests - by using a sieve script which discards duplicates. It works well in most cases. When the recipient is over quota, it works weirdly.
This is the log of the first delivery attempt. It fails with tempfail Quota exceeded, as one would expect:
AF4481700032: to=<?@?>, relay=?[private/dovecot-lmtp], delay=0.05, delays=0.05/0/0/0, dsn=4.2.2, status=deferred (host ?[private/dovecot-lmtp] said: 452 4.2.2 <?@?> Quota exceeded (mailbox for user is full) (in reply to end of DATA command))
Approximately 10 minutes later, another attempt:
dovecot: lmtp(?)<1742912><+EYHBXjidmBAmBoAcAY70w>: sieve: msgid=<489132c2-7b77-cd2f-ce60-439f6558ddcf@?>: marked message to be discarded if not explicitly delivered (discard action)
postfix/lmtp[1742691]: AF4481700032: to=<?@?>, relay=?[private/dovecot-lmtp], delay=431, delays=431/0/0/0, dsn=2.0.0, status=sent (250 2.0.0 <?@?> +EYHBXjidmBAmBoAcAY70w Saved)
postfix/qmgr[421343]: AF4481700032: removed
It seems to me that Dovecot's sieve recorded the message ID during the first delivery attempt, despite the fact that delivery was rejected.
During second delivery attempt, Dovecot's sieve apparently thinks it's seeing a duplicate, and discards the mail.
Is there any workaround for this kind of situation?