I have not tried these (disclaimer!), but here are a couple of options:
https://webapps.earth.illinois.edu/dist/dedupe/
Here's one that runs in Thunderbird. If you set up an IMAP account in Thunderbird, and the program works as described, it will clean up the webmail folders as well, because the webmail folders are the same as IMAP deals with:
https://addons.mozilla.org/en-US/thunderbird/addon/remove-duplicate-messages/