On 08 Nov 2016, Jon LaBadie wrote:
> A year or more back someone posted a technique for
> tagging duplicate mails in a mailbox. It used T~=.
> The tagged mails could then be deleted.
>
> I'm now using mutt on another system and the T~=
> sequence does not work and I can't see what I
> might have added to my .muttrc to make it work.
Please, found attached a script in Python for do that! I have been used it a
lot. Should be it work for you too.
--
Marcelo
import mailbox
import glob
import os.path
def dedupe(maildir):
'''Removes duplicates from the given dir'''
box = mailbox.Maildir(maildir, create=False)
box.lock()
# Set of Message IDs we have seen
seen = set()
# Set of message keys to delete
delete = set()
# Search for messages to delete
for (key, message) in box.iteritems():
mid = message['Message-Id']
# If we have seen this Message ID before,
# remember it for deletion
if mid in seen:
delete.add(key)
seen.add(mid)
# Delete the messages
for key in delete:
box.remove(key)
box.close()
# Iterate over all subdirectories as maildirs
for dir in glob.glob('*'):
if not os.path.isdir(dir): continue
dedupe(dir)