Cleaning up dovecot duplicates

There doesn't seem to be an internal dovecot tool for eliminating duplicate emails -- and over time, duplicates seem to accumulate endlessly.

My strategy: import the mailbox to DevonThink Pro, which automatically ignores duplicate imports. Then export the messages to an mbox. Use BBEdit to replace the " " with a newline (to properly delimit messages), import the mbox into Mail, and then rebuild the final mailbox so that Mail correctly indexes attachments.