Delete Duplicate Email messages from Server

I am sure a lot of us have faced this problem of receiving multiple email copies specially when the addresses are forwarded.

I had a setup where user1@mydomain.com, user2@mydomain.com and user3@mydomain.com were forwarded to collect@mydomain.com . Any email addressed to all 4, used to end up 4 times in collect box. This was an archieval box so multiple copies not only wasted the server space and resources but also made it difficult to search a particular message.

I was looking for a script that could run on the server and delete teh mails from the server itself, without me having to downlaod them first to the PC. There are plugins for Thunderbird that would let you delete the duplicate messages once you have downloaded them , but I wanted an on the server solution

The solution came from a script written by Quentin http://www.qandr.org/quentin/software/imapdedup. It’s a python script and it marks all the duplicate messages as Deleted on the email server itself.

from command line you can run it simply by specifying your mail server, user id , password and mailbox name . You can also run it with -v to see what goes on.

path_to_imapdedup/imapdedup.py -s imap.myisp.com -u myuserid -w secretpassword -n MAILBOXNAME

This is an excellent solution for anyone looking to delete large number of duplicate emails straight from the server without having to download the message first.