In case somehow, you got duplicate mails in a maildir, like me, maybe this is helpful to you:
find /var/mail/user -type d -name cur -print0 | xargs -0 /usr/bin/fdupes -n | less
Of course you need fdupes installed. On debian:
apt-get install fdupes
The above command is the dry run, showing you the duplicates.
Then to delete the duplicates, leaving only the first found file:
find /var/mail/user -type d -name cur -print0 | xargs -0 /usr/bin/fdupes -ndN | less
Use the same thing again with “new” instead of “cur” if you have duplicate unread mails. This only looks at duplicates within the same folder, so you can also safely run it on /var/mail for all users.
Note that this assumes the duplicates have exactly the same content. If you want to clean duplicates which are a bit different, consider this tool.
Update 2018: Three years later, I had the same problem, googled it and found my own blog post 😉 And it again solved the problem 🙂
It does compare emails from different subfolders though, it will delete one of those two emails if their content is the same:
./.Trash/cur/xxxx
./cur/yyyy
Comment by Monkey — 3. July 2024 @ 15:33