+2 votes

MimeMessage.MessageId is unique in accross the folder so why Mail.dll not using it as unique id? Is there a way we can convert uid from Messageid? Or we can use Messageid instead of uid?

by (760 points)
edited by

1 Answer

+2 votes

Because this is how IMAP works. IMAP protocol uses UIDs, it doesn't use Message-IDs.

Message-ID is not unique across folders. You can upload exactly the same message (with the same Message-ID) to two different folders. Most servers would even allow uploading the same message twice to the same folder.

You can search IMAP for particular Message-ID of course - use Imap.Search and Expression.MessageId:

List<long> uids = imap.Search(Expression.MessageId("1234@example.com"));

Side note:
Message-ID is assigned by client, just before sending email, there is no guarantee for it to be unique. There's also no guarantee that this email header is even present.

by (301k points)
Thanks for very quick response, I had use Message-ID everywhere in my application so just want to know is there any way we can convert message-id to UID?
You can use Imap.Search and Expression.MessageId.

Please note that sooner or later you'll encounter emails without this header at all.
...