EWS ExtendedPropertyDefinition搜索过滤器失效问题求助
O365 EWS自定义扩展属性搜索过滤器突然失效,返回全部邮件
我们用C#通过EWS对接Exchange的代码已运行十余年,目前几乎所有客户都迁移至Office365,此前代码在O365上运行正常,但近一个月出现问题。
我们的软件处理Exchange邮箱收到的邮件,该邮箱同时供人工和软件使用,因此通过ExtendedProperty跟踪已处理的邮件,核心代码如下:
// Build our extended property definition Guid readByEmailComponentGUID = new Guid("{FCF74ABF-684E-4cc7-8A83-B36D3A209219}"); //GUID for our property ExtendedPropertyDefinition X_READBYCOMPONENT = new ExtendedPropertyDefinition(readByEmailComponentGUID, "X_READBYCOMPONENT", MapiPropertyType.Boolean); //Settings and name for our property // Create a search filter for querying EWS SearchFilter.SearchFilterCollection srchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or); srchFilter.Add(new SearchFilter.Not(new SearchFilter.Exists(X_READBYCOMPONENT))); //Show messages that do not have our new property (thus have never been received) srchFilter.Add(new SearchFilter.IsEqualTo(X_READBYCOMPONENT, false)); //Show messages that have our new property, but it's set to false (to re-receive) ItemView view = new ItemView(250, 0, OffsetBasePoint.Beginning); // Query EWS with our search filter and our view FindItemsResults<Item> findResults = EWSService.FindItems("Inbox", srchFilter, view); // Process the results of our search foreach (Item item in findResults){ // Check to see if this email has our internal read flag on it, and if it does, do not process it again. ExtendedProperty ReadByComponentFlag = item.ExtendedProperties.FirstOrDefault(itm => itm.PropertyDefinition == X_READBYCOMPONENT); if (!(ReadByComponentFlag is null) && (bool)ReadByComponentFlag.Value == true) { continue; } if (item is EmailMessage){ EmailMessage em = item as EmailMessage; //Load the email message // process the mail message and when that's done mark it as read em.SetExtendedProperty(X_READBYCOMPONENT, true); //Sets our new property to TRUE to exclude this email from future receive actions em.Update(ConflictResolutionMode.NeverOverwrite); } }
这段代码自2011年以来运行良好,但近一个月,O365客户的搜索过滤器完全失效——EWS会返回收件箱内所有邮件。手动检查邮件的扩展属性,确认我们的自定义属性确实存在且值为true,但过滤器无法正确过滤掉这些邮件。
目前我们临时在代码中加入了手动检查扩展属性并跳过已处理邮件的逻辑(代码中已体现),但部分邮箱有14000封邮件,每次运行都拉取全部邮件显然不是长期可行的方案。
请问:
- O365上的EWS处理此类自定义扩展属性过滤器的逻辑是否有变更?
- 是否有其他开发者遇到过类似问题?
内容的提问来源于stack exchange,提问作者Mark Henderson
相关产品推荐
相关产品推荐

