This project is read-only.

How to delete duplicate messages??

Topics: Help requests
Dec 31, 2015 at 7:44 PM
Could someone guide me with a little bit of starter code on how I can delete duplicate emails from a folder? I've read that each message has a unique identifier in it, so I figure I need to loop over all the message in a folder, maybe store the message id to an array or list or dictionary if it is not already present in there, and delete the message if it is already in there.
Jan 1, 2016 at 3:41 AM
Ok, I think I have discovered how to do this, but I need access to the Message-ID string value of each email in the target folder. However, I cannot find where the read this value from the Message object.

The only way I see to do this is to call the DownloadRawMessage() method and then parse out the Message-ID value from the full email message as the string returned by this method call.

So, is there a simpler way to access the Message-ID string?
Jan 1, 2016 at 5:34 PM
I'm not sure how to do it with ImapX, but the IMAP protocol allows you to FETCH the ENVELOPE of a message, which is essentially a pre-parsed set of the most important headers of a message (including the Message-ID).

That said, a Message-ID is not guaranteed to be unique, so blindly deleting messages with identical Message-IDs is dangerous.