Let's say you are building an application that syncs message bodies and metadata down from EWS. Getting your initial state synchronized is fairly straightforward: call SyncFolderHierarchy
to get the folder list, SyncFolderItems
to get the message ItemIds, and GetItem
to get the message bodies and metadata.
Things become a bit more complicated when trying to track messages through moves. After a move, calls to SyncFolderItems
would return a Create in one folder and a Delete in another. You'd like to correlate these so that the client could avoid redownloading the message body and attachments. (Also, so that the client doesn't lose any metadata it had associated with its local copy.) However, moving a message between folders changes its EWS ItemId, so the ItemId can't be used to correlate the Create and the Delete.
The EWS documentation suggests subscribing to streaming notifications, which do indeed support Move events. But streaming notifications aren't buffered when the stream is not connected, so you still have to bring the client back in sync before establishing a streaming connection. So streaming notifications can't be a full correlate-through-moves solution.
Another EWS option is subscribing to pull notifications. Like streaming notifications, pull notifications support Move events. And unlike streaming notifications, pull subscriptions buffer changes. But if your client is offline when the pull subscription expires, you are back in the same situation. (Still, since a pull subscription can be scoped to last a full day, this may still be workable.)
The last option is using something other than the ItemId to correlate moved items through SyncFolderItems
:
PR_SEARCH_KEY
works through moves but has problems with copies (as the copy ends up with the samePR_SEARCH_KEY
as the original)PR_ENTRYID
seems like it'd be workable for this purpose and seems better thanPR_RECORD_KEY
:
A MAPI store provider assigns a unique ID string when an item is created in its store. Therefore, the EntryID property is not set for a Microsoft Outlook item until it is saved or sent. The EntryID changes when an item is moved into another store, for example, from your Inbox to a Microsoft Exchange Server public folder, or from one Personal Folders (.pst) file to another .pst file. Solutions should not depend on the EntryID property to be unique unless items will not be moved. The EntryID property returns a MAPI long-term EntryID.
So... What's the right way to correlate items through moves via EWS?