You are hereFiltering duplicate emails with procmail

Filtering duplicate emails with procmail


By thomas - Posted on 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...

Tags

Perfect, short, sweet, and thanks for the explanation. This is just what I needed, but my friends told me to go with a client-side solution. I told them I have committed to central email filtering and this won't stop me :)

[...] taki trick ;) ¿eby "nie duplikowa³"/"nie dostarcza³" duplikatu wiadomo¶ci. http://ramblings.narrabilis.com/wp/f...with-procmail/ http://partmaps.org/era/procmail/tony.html [...]

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options