#! /usr/bin/python import os import sys import email import hashlib dups = {} for root, dirs, files in os.walk('/home/pogma/Maildir'): for fname in files: try: fobj = open(os.path.join(root,fname)) msg = email.message_from_file(fobj) fobj.close() except: fobj.close() continue msg.__delitem__('Received') hash = hashlib.md5(msg.as_string()).hexdigest() if not dups.has_key(hash): dups[hash] = os.path.join(root,fname) else: os.unlink(os.path.join(root,fname))