Disclaimer: at some point I found this page describing how to delete duplicate e-mail messages with mutt. Unfortunately the page is not up anymore (HTTP 404) and I took the liberty to post it on my blog. Anyway, credit goes to Marianne Promberger. The original page was here: http://promberger.info/linux/2008/03/31/mutt-delete-duplicate-e-mail-messages/
Here we go:
Sometimes, if you consolidate different mailboxes where some of the messages are in both mailboxes, you end up with duplicates.
With mutt, it is really easy to delete one copy of each duplicate. I got this tip from here.
You need to have
set duplicate_threads = yes, either put it in your
~/.muttrc, or check whether it is on by default (it is for me). To see the value of a variable, while you’re running mutt, say:set ?duplicate_threads
and it will display the current value (note the leading colon, and of course replace “duplicate_threads” with the variable name you want to see).
You also need to have your mailbox sorted by message threads. This is a nice feature in general, similar to the messages threads in Gmail (but mutt’s implementation is much more user friendly, in my opinion). If you haven’t already
set sort=threadsin your
~/.muttrc, you can sort “on the fly” while you’re in a mailbox: type
o(to sort; mutt then asks for the criterion to sort on, and tells you the options) followed by
Tto tag a certain pattern, put in
~=as the pattern. Duplicates (one copy of each message that mutt sees twice in the folder) are now tagged. To delete them, either type just
d(this will work if you have
set auto_tag=yes), or type
;to apply the next command to all tagged messages, then hit
Actually, it’s much easier, you can skip the tagging step and just do
D(for “delete matching pattern” followed by
~=. If you’re adventurous, you can set Mutt to automatically rid your mailboxes of duplicates using a
folder-hook, like this (in your
~/.muttrc)folder-hook . push "<delete-pattern>~=<enter>"
This is handy together withfolder-hook . 'set record="^"'
which always puts your “sent” copy into the current mailbox — handy for developing meaningful threads of incoming mails and replies. However, of course it results in duplicates if you are on the cc or if the mail is going to a mailing list you’re subscribed to. Enter the above folder-hook — no more duplicates.
If you’re even more adventurous, you could add updating your mailbox (i.e., purging messages marked for deletion) to the above folder-hook, like this:folder-hook . push "<delete-pattern>~=<enter>$"