Woes with copy operation and extended properties in EWS

276 Views Asked by At

I am tasked with bidirectioanlly synching contact folders in two mailboxes with a service. Please bear with me, as this is the first time I'm using EWS in C#.

In order to uniquely identify items and track changes for synching, I am utilizing SyncFolderHierarchy() for subfolders and SyncFolderItems() for items in each subfolder, while tracking the syncstate.

Since the folder/item IDs are depdendent on the mailbox, on initial sync, as well as on Create operations, I am tagging synched items with an extended property via Item.SetExtendedProperty()

This works really well, but I have run into a caveat.

When a user copies and pastes a folder or contact in Outlook, it also copies the unique ID (extended property), making it not-so-unique anymore. In that case, I now have two items in a mailbox with the same "unique" ID, and now have an ambiguous match for the item.

Basically:

  1. SyncFolderItems() is invoked, and sync state saved
  2. Item is tagged with unique ID if it doesn't have one
  3. User copies and pastes the item
  4. SyncFolderItems() is invoked (with previous sync state), returns a Create event for user-copied item
  5. Item that is created already has a unique ID

Now, one might argue just overwrite the unique ID for an item in a create event.

However, this leads to the following issue:

When I sync a new item from mailbox A into mailbox B, I also create an item. Once SyncFolderItems() on mailbox A is now invoked, I also retrieve a Create event for my own item, which in this case legitimately already has a unique ID assigned that must not be overwritten.

I basically see two options:

  • Somehow prevent this extended property from being copyable

  • Prevent EWS from sending a create for an item I created myself. I am aware I can ignore ItemIDs in a SyncFolderItems() call, but I am not sure how I should track the item IDs across calls because they may change according to the documentation

Does anyone have any suggestions on how to approach this differently or implement either option??

1

There are 1 best solutions below

4
On BEST ANSWER

The Exchange id should really be your unique id as well. It is really not worth it to keep your id on the item itself - firstly, that requires a modification of that item (and that will generate a change event even though it was you who caused the change), and secondly, as you have already noticed, you can end up with duplicates or triplicates of the same item.

It is even worse for the appointments - each incoming appointment update causes Outlook to recreate the appointment, causing a new id to be used and wiping out your custom property.