gpt4 book ai didi

c# - 在文件夹上使用 FindItems 时,EWS SearchFilter 不适用于某些电子邮件地址

转载 作者:太空宇宙 更新时间:2023-11-03 12:45:27 27 4
gpt4 key购买 nike

下面的代码返回零个项目。

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);

当我在 searchFilter 中使用特定的电子邮件地址时,即使文件夹中存在邮件项目,列表有时也会包含 0 个项目。

当我不使用带有 FindItems 的 SearchFilter 时,它会出现在列表中。

为什么 SearchFilter 不起作用?

最佳答案

首先。

如果您只想查找一个电子邮件地址,则不需要搜索过滤器列表

SearchFilter> slist = new List<SearchFilter> ();

现在谈谈一些建议:

  1. 我建议使用查询字符串而不是 SearchFilter

     // Find all items where the From: contains "some@emailaddress.com".
    string filter= "From:\"some@emailaddress.com\"";

    来源:https://msdn.microsoft.com/en-us/library/office/dn579420(v=exchg.150).aspx

  2. 不要在 ItemView 中拉取 99 个项目,而是拉取 20 个并使用分页

    ItemView messageView = new ItemView(20, 0, OffsetBasePoint.Beginning);
  3. 仅加载您需要的属性

    messageView.PropertySet = BasePropertySet.IdOnly;
  4. 定义您要搜索的深度

    messageView.Traversal = ItemTraversal.Shallow

下面的代码只是我过去如何使用 findItems 方法在我自己的项目中使用 VB 的示例...用于演示目的

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

关于c# - 在文件夹上使用 FindItems 时,EWS SearchFilter 不适用于某些电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37486129/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com