Postfix aliases and duplicate e-mails, how to fix?
There is a way how to do it, but not using Postfix itself.
If you are using a reasonably recent Dovecot with Pigeonhole implementation of Sieve, there is a special extension that can be used for on-delivery deduplication. In Dovecot older than 2.2.18, the name of this extension is "vnd.dovecot.duplicate" and it's disabled by default, in newer releases the extension is called "duplicate" and should be already enabled, but enabling it explicitly won't harm.
/etc/dovecot/conf.d/90-sieve.conf:
plugin {
sieve = ~/.dovecot.sieve
sieve_dir = ~/sieve
sieve_before = /mnt/mail/users/global_sieve/deduplicate.sieve
# sieve_before2 = /mnt/mail/users/global_sieve/antispam.sieve
sieve_extensions = +vnd.dovecot.duplicate # for dovecot < 2.2.18
#sieve_extensions = +duplicate # for dovecot >= 2.2.18
}
Then create the sieve script to handle the deduplication itself (you can adjust the filename as you see fit).
/mnt/mail/users/global_sieve/deduplicate.sieve:
require "vnd.dovecot.duplicate"; # for dovecot < 2.2.18
# require "duplicate"; # for dovecot >= 2.2.18
if duplicate {
discard;
stop;
}
Compile the script using sievec and make sure the script is readable by dovecot user. More in Dovecot docs.
If you are using Cyrus, there is a a duplicate message delivery suppression feature that can be enabled using suppress_duplicates = yes
.
Postfix has no idea about duplicate emails due to the way it's structured. It is possible to do what you're suggesting by using procmail as your delivery agent.
Essentially, each message coming from a client should be delivered with a unique Message-Id. In the case that it's delivered to multiple people, the Message-Id should be the same, so we save any Message-Id
headers we've seen and discard and future ones that match that list.
From http://novosial.org/procmail/
:0 Wh: msgid.lock
| formail -D 8192 ~/.procmail/msgid.cache
A solution that work for me is add -o receive_override_options=no_address_mappings
on master.cf
Here the doc: http://www.postfix.org/postconf.5.html#receive_override_options