Just passing on a hint of a very useful piece of code:
I had to import a lot of email into Nethserver from Outlook PST Files and, as can be expected from this software/process - with a few import failures along the way - there were several duplicates across a number of IMAP folders.
In the past I would look to attack it from Outlook, but this time looked at it from the server end.
IMAPdedupe was the perfect solution. It worked ‘out of the box’ as Python was already installed.
Stay safe and well.