Zend certified PHP/Magento developer

Migrate from POP to IMAP on Gmail without duplicating emails and preserving local folder structure

We are on G Suite and have one user who is still on POP and has lots of folders and locally stored emails in Thunderbird. I want to migrate them to IMAP and I’m fine with recreating all the labels and folders manually. However, how do I move/label all the messages in those folders into the new IMAP structure without duplicating all the messages?

I was intending to just copy the emails from the Thunderbird local folders up into the IMAP folder structure, but I suspect that will end up with duplicate emails.

Is there any way to avoid this or a simple way to de-duplicate after it’s done? I don’t want to delete messages in the current accounts All Mail folder and I don’t want to use a new empty account.