EWS Managed API-Equivalent of IMAP UID for an email message? RRS feed

  • Question

  • I'm trying to write an app that can use a cached message ID to retrieve the contents of the message from a mailbox at a later time.  The system needs to be able to work with either IMAP or Exchange web services managed API.  I started with testing out an IMAP implementation, and I can get the UID of a message (as defined in RFC 3501).  Using that UID, I can go back and retrieve a message just fine.  On the EWSMA side though, I can't seem to figure out an equivalent message ID.  In the IMAP world, the UID is an integer, but any message IDs I get off an EmailMessage are Guids.  What I want to be able to do is call something like "EmailMessage.Bind(m_exchange, newItemId("8"));" to bind to a message with UID 8 in the current mailbox. 

    Is there a way to convert a UID like this, or a way that I could uniquely identify a message using either/both of these methods?  My alternative, I suppose, is to store either the IMAP UID or exchange message ID, and if the protocol changes, invalidate and re-search based on the other headers I already know about.

    Wednesday, October 9, 2013 6:53 PM

All replies

  • The only thing that will work in EWS to get a Message (using Bind or GetItem) is the ewsId. The only way of getting the EWSid is though EWS so if your getting a Message via IMAP you won't be able to able to access the EWSId (or any of the other Extended Mapi properties).

    EWS has a ConvertID operation but this will only allow converting between MAPI, EWS and OWA identifiers. The only Id that would be interchangeable between and IMAP and EWS session would be the Internet Message Id. So you could search for the Message based on that Id and then access it eg.

    ItemView ivew = new ItemView(1); service.TraceEnabled = true; ExtendedPropertyDefinition PidTagInternetMessageId = new ExtendedPropertyDefinition(4149, MapiPropertyType.String); SearchFilter sf = new SearchFilter.IsEqualTo(PidTagInternetMessageId, MessageID); FindItemsResults<Item> iCol = service.FindItems(WellKnownFolderName.Inbox, sf, ivew); foreach (Item item in iCol.Items) {
    Console.WriteLine(item.Subject); }

     Be careful if you are going to store the ewsId because these change if the message is moved between folders.


    • Proposed as answer by Désiré GOVIN Thursday, October 10, 2013 7:41 AM
    Thursday, October 10, 2013 4:40 AM