通过EWS移动来关联消息

时间:2015-12-11 23:50:35

标签: office365 exchangewebservices

假设您正在构建一个从EWS同步消息正文和元数据的应用程序。让您的初始状态同步非常简单:致电SyncFolderHierarchy to get the folder list, SyncFolderItems to get the message ItemIds, and GetItem to get the message bodies and metadata.

尝试通过移动跟踪消息时,事情变得有点复杂。移动后,对SyncFolderItems的调用将在一个文件夹中返回Create,在另一个文件夹中返回Delete。您希望关联这些内容,以便客户端可以避免重新加载邮件正文和附件。 (另外,客户端不会丢失与其本地副本关联的任何元数据。)但是,在文件夹之间移动消息会更改其EWS ItemId,因此ItemId不能用于关联Create和删除。

EWS文档建议subscribing to streaming notifications,它确实支持Move事件。但是流式传输通知aren't buffered when the stream is not connected,因此您仍然需要在建立流式连接之前使客户端恢复同步。因此,流式传输通知不能成为一个完整的相关移动解决方案。

另一个EWS选项是subscribing to pull notifications。与流式通知一样,拉动通知支持移动事件。与流式通知不同,拉订阅缓冲区更改。但是,如果您的客户端在请求订阅到期时处于脱机状态,那么您将回到相同的状态。 (不过,自a pull subscription can be scoped to last a full day起,这可能仍然可行。)

最后一个选项是使用ItemId以外的其他内容通过SyncFolderItems关联已移动的项目:

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.

那么...... 正确通过EWS移动来关联项目的方式是什么?

2 个答案:

答案 0 :(得分:5)

有两件事可以帮到你:

第一种方法

我们通过为每个项目(在我们的案例中为日历项目)提供包含EWS项目ID副本的用户定义属性(又名扩展属性)来解决这个问题(每当我们写/更新它)。

每当我们读取项目以进行同步时,我们都会检查该属性是否仍与EWS项目ID匹配。如果没有,我们知道该项已被移动并相应地处理它(我们清除了用户定义的属性)。

与其他一些用户定义的簿记属性一起,这可以让我们维护Exchange中的项目与应用程序中的项目之间的完整性。

第二种方法

有一些边缘情况,这不起作用(但我们忽略它们)。对于那些,使用EWS项ID进行跟踪不再有效,建议使用UID / PidLidGlobalObject属性。我没有必要实际实现这一点,但这里有一些参考来帮助你入门:

"Exchange calendar: Is ConversationId a good identifier of master events for FindItem occurrences?"
"The appointment.Id.UniqueID changed"
"EWS API- Differences in ICalUid returned when appointments are created by Office 365 account vs. Microsoft Outlook Mac Client"
"EWS: UID not always the same for orphaned instances of the same meeting"

"Property: UID"
"PidLidGlobalObjectId Canonical Property"
"PidLidCleanGlobalObjectId Canonical Property"
"Getting GlobalObjectID from UID(Appointment created from IPhone)"
"Developer information about the calendar changes in Outlook 2003 Service Pack 2, in Exchange Server 2003 Service Pack 2, and in later versions of Exchange Server and of Outlook"

"Working with extended properties by using the EWS Managed API 2.0"

我无法详细说明要使用的代码,因为我们的应用程序是用Delphi编写的,并且只使用SOAP调用来同步日历项目

答案 1 :(得分:0)

您拥有的另一个选项是消息 ID 字段(来自 RFC 5322),即来自 Graph API message resource 的 internetMessageId。该 ID 在移动中保持不变。但是,它在副本中也保持不变,这可能是您喜欢的,也可能不是。