Filtering duplicate emails with procmail

By thomas, 20 June, 2006
We have a few departments on campus and each user has a username in at least one department plus the top level domain. This means that if an email is sent to username@dept.company.net and there is a cc to username@company.net Then username will get the email twice. After playing around I found that procmail can track the messageid's of emails in a file, so i have this simple rule to filter out. PMDIR=$HOME/.procmail :0 Whc: msgid.lock | formail -D 4096 $PMDIR/idcache :0 a: Mail/duplicates

:0 Whc: msgid.lock This sends the headers to formail and makes a carbon copy of the mail and creates a lock file while we are doing this. | formail -D 4096 $PMDIR/idcache This pipes the output of the previous line to formail, formail will append the msgid of the message to the file idcache if it doesn't already exist. If the msgid exists, then it will exit with success, if it does not then it will append the msgid to the file (removing anything over 4096 bytes) and return failure. :0 a: We use the a: to see if there was success on the previous rule. Mail/duplicates We then send the message to the folder Mail/duplicates. We could send to /dev/null, but I'm too chicken for that...