C# 在文件夹上使用FindItems时,EWS SearchFilter无法处理某些电子邮件地址
下面的代码返回零项C# 在文件夹上使用FindItems时,EWS SearchFilter无法处理某些电子邮件地址,c#,exchangewebservices,C#,Exchangewebservices,下面的代码返回零项 EWSService = new ExchangeService(ExchangeVersion.Exchange2010_SP1); EWSService.TraceListener = tr; EWSService.TraceFlags = TraceFlags.DebugMessage | TraceFlags.EwsRequest | TraceFlags.EwsResponse; EWSServ
EWSService = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
EWSService.TraceListener = tr;
EWSService.TraceFlags = TraceFlags.DebugMessage | TraceFlags.EwsRequest | TraceFlags.EwsResponse;
EWSService.TraceEnabled = true;
EWSService.Credentials = new WebCredentials(user, psw,domain);
EWSService.Url = new Uri("https://----/EWS/Exchange.asmx");
FolderId id = Test(EWSService, "inbox", null);
Folder source = Microsoft.Exchange.WebServices.Data.Folder.Bind(EWSService, id);
SearchFilter> slist = new List<SearchFilter> ();
Add(new SearchFilter.IsEqualTo(EmailMessageSchema.From, "some@emailaddress.com"));
SearchFilter filter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, slist);
ItemView messageView = new ItemView(99);
FindItemsResults<Item> list = source.FindItems(filter,messageView);
EWSService=新的ExchangeService(ExchangeVersion.Exchange2010_SP1);
EWSService.TraceListener=tr;
EWSService.TraceFlags=TraceFlags.DebugMessage | TraceFlags.EwsRequest | TraceFlags.EwsResponse;
EWSService.TraceEnabled=true;
EWSService.Credentials=新的WebCredentials(用户、psw、域);
EWSService.Url=新Uri(“https://----/EWS/Exchange.asmx");
FolderId=Test(EWSService,“收件箱”,null);
文件夹源=Microsoft.Exchange.WebServices.Data.Folder.Bind(EWSService,id);
SearchFilter>slist=新列表();
添加(新的SearchFilter.IsEqualTo(EmailMessageSchema.From)some@emailaddress.com"));
SearchFilter filter=新建SearchFilter.SearchFilterCollection(LogicalOperator.Or,slist);
ItemView messageView=新的ItemView(99);
FindItemsResults列表=source.FindItems(过滤器,messageView);
当我在searchFilter中使用特定电子邮件地址时,该列表有时包含0个项目,即使该邮件项目存在于文件夹中
当我不对FindItems使用SearchFilter时,它会出现在列表中
为什么SearchFilter不工作?首先
如果您只想查找一个电子邮件地址,则不需要Searchfilter列表
SearchFilter> slist = new List<SearchFilter> ();
资料来源:
ItemView messageView = new ItemView(20, 0, OffsetBasePoint.Beginning);
messageView.PropertySet = BasePropertySet.IdOnly;
messageView.Traversal = ItemTraversal.Shallow
Private Function GetAllSyncedContactIdsInExchange(pService As ExchangeService) As List(Of Integer)
Dim oInternalContactIdDefinition As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, conContactIdPropertyName, MapiPropertyType.Integer)
Dim oInternalContactIdFilter As New SearchFilter.Exists(oInternalContactIdDefinition)
Dim oResults As FindItemsResults(Of Item) = Nothing
Dim oPropertySet As New PropertySet(oInternalContactIdDefinition)
Dim lstSyncedContactIds As New List(Of Integer)
Dim intDBId As Integer
Dim lstEESContactFolders As List(Of FolderId) = GetAllCustomEESFolderIds(pService)
For Each oFolderId As FolderId In lstEESContactFolders
Dim blnMoreAvailable As Boolean = True
Dim intSearchOffset As Integer = 0
Dim oView As New ItemView(conMaxChangesReturned, intSearchOffset, OffsetBasePoint.Beginning)
oView.PropertySet = BasePropertySet.IdOnly
Do While blnMoreAvailable
oResults = pService.FindItems(oFolderId, oInternalContactIdFilter, oView)
blnMoreAvailable = oResults.MoreAvailable
If Not IsNothing(oResults) AndAlso oResults.Items.Count > 0 Then
pService.LoadPropertiesForItems(oResults, oPropertySet)
For Each oExchangeItem As Item In oResults.Items
If oExchangeItem.TryGetProperty(oInternalContactIdDefinition, intDB2Id) Then
lstSyncedContactIds.Add(intDBId)
End If
Next
If blnMoreAvailable Then oView.Offset = oView.Offset + conMaxChangesReturned
End If
Loop
Next
Return lstSyncedContactIds
End Function
谢谢你的回复。我上面的代码是从一个项目改编的代码。搜索筛选器列表是必需的,因为在我的项目中可能有多个项目。我将尝试您的建议并发布我的结果。我使用查询字符串(最多包含10,20,…个电子邮件地址)尝试了您的答案,但FindItems的执行时间为某些邮箱的3到4分钟。每次执行新的FindItems都会花费大量时间。
Private Function GetAllSyncedContactIdsInExchange(pService As ExchangeService) As List(Of Integer)
Dim oInternalContactIdDefinition As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, conContactIdPropertyName, MapiPropertyType.Integer)
Dim oInternalContactIdFilter As New SearchFilter.Exists(oInternalContactIdDefinition)
Dim oResults As FindItemsResults(Of Item) = Nothing
Dim oPropertySet As New PropertySet(oInternalContactIdDefinition)
Dim lstSyncedContactIds As New List(Of Integer)
Dim intDBId As Integer
Dim lstEESContactFolders As List(Of FolderId) = GetAllCustomEESFolderIds(pService)
For Each oFolderId As FolderId In lstEESContactFolders
Dim blnMoreAvailable As Boolean = True
Dim intSearchOffset As Integer = 0
Dim oView As New ItemView(conMaxChangesReturned, intSearchOffset, OffsetBasePoint.Beginning)
oView.PropertySet = BasePropertySet.IdOnly
Do While blnMoreAvailable
oResults = pService.FindItems(oFolderId, oInternalContactIdFilter, oView)
blnMoreAvailable = oResults.MoreAvailable
If Not IsNothing(oResults) AndAlso oResults.Items.Count > 0 Then
pService.LoadPropertiesForItems(oResults, oPropertySet)
For Each oExchangeItem As Item In oResults.Items
If oExchangeItem.TryGetProperty(oInternalContactIdDefinition, intDB2Id) Then
lstSyncedContactIds.Add(intDBId)
End If
Next
If blnMoreAvailable Then oView.Offset = oView.Offset + conMaxChangesReturned
End If
Loop
Next
Return lstSyncedContactIds
End Function