2016-05-31 22 views
0

我正在使用Office.context.mailbox.makeEwsRequestAsync方法向EWS发送以下XML查询。带有“AND”和“OR”子句的EWS搜索查询

查询字符串值需要匹配主题或来自字段;并且电子邮件必须属于“MY_CATEGORY”类别。我无法执行最后一项要求。我究竟做错了什么?

<?xml version="1.0" encoding="utf-8"?> 
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Header> 
     <t:RequestServerVersion Version="Exchange2013_SP1" /> 
    </soap:Header> 
    <soap:Body> 
     <m:FindItem Traversal="Shallow"> 
     <m:ItemShape> 
      <t:BaseShape>AllProperties</t:BaseShape> 
     </m:ItemShape> 
     <m:IndexedPageItemView MaxEntriesReturned="10" Offset="0" BasePoint="Beginning" /> 
     <m:Restriction> 
     <t:Or> 
      <t:Contains ContainmentMode="Substring" ContainmentComparison="IgnoreCase"> 
      <t:FieldURI FieldURI="item:Subject" /> 
      <t:Constant Value="query string" /> 
      </t:Contains> 
      <t:Contains ContainmentMode="Substring" ContainmentComparison="IgnoreCase"> 
      <t:FieldURI FieldURI="message:From" /> 
      <t:Constant Value="query string" /> 
      </t:Contains> 
     </t:Or> 
     <t:And> 
      <t:Contains ContainmentMode="FullString" ContainmentComparison="IgnoreCase"> 
      <t:FieldURI FieldURI="item:Categories" /> 
      <t:Constant Value="MY_CATEGORY" /> 
      </t:Contains> 
     </t:And> 
     </m:Restriction> 
     <m:ParentFolderIds> 
      <t:DistinguishedFolderId Id="inbox" /> 
      <t:DistinguishedFolderId Id="sentitems" /> 
     </m:ParentFolderIds> 
     </m:FindItem> 
    </soap:Body> 
    </soap:Envelope> 

回答

0

类别是多值字符串,因此您使用的searchfilters将不适用于这些类型的值。您可以使用Exchange 2010及以上版本的AQS来搜索类别以及搜索其他字段。例如

<?xml version="1.0" encoding="utf-8"?> 
 
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
 
    <soap:Header> 
 
     <t:RequestServerVersion Version="Exchange2013_SP1" /> 
 
    </soap:Header> 
 
    <soap:Body> 
 
     <m:FindItem Traversal="Shallow"> 
 
     <m:ItemShape> 
 
      <t:BaseShape>IdOnly</t:BaseShape> 
 
      <t:AdditionalProperties> 
 
      <t:FieldURI FieldURI="item:Subject" /> 
 
      <t:FieldURI FieldURI="item:DisplayTo" /> 
 
      <t:FieldURI FieldURI="item:DisplayCc" /> 
 
      <t:FieldURI FieldURI="item:DateTimeReceived" /> 
 
      <t:FieldURI FieldURI="item:HasAttachments" /> 
 
      <t:FieldURI FieldURI="item:ItemClass" /> 
 
      </t:AdditionalProperties> 
 
     </m:ItemShape> 
 
     <m:IndexedPageItemView MaxEntriesReturned="250" Offset="0" BasePoint="Beginning" /> 
 
     <m:SortOrder> 
 
      <t:FieldOrder Order="Ascending"> 
 
      <t:FieldURI FieldURI="contacts:DisplayName" /> 
 
      </t:FieldOrder> 
 
     </m:SortOrder> 
 
     <m:ParentFolderIds> 
 
      <t:FolderId Id="AQ..." /> 
 
     </m:ParentFolderIds> 
 
     <m:QueryString>System.Category:Green AND (From:'Glen Scales' OR Subject:test) </m:QueryString> 
 
     </m:FindItem> 
 
    </soap:Body> 
 
    </soap:Envelope>

+0

但会与多个文件夹这项工作?请注意,原始查询正在搜索收件箱和发送的文件夹。 –

+0

是否可以使用javascript调用创建EWS“搜索文件夹”? –

+0

它应该适用于多个文件夹,但您应该自己尝试,您可以使用EWS创建搜索文件夹,例如https://msdn.microsoft.com/zh-cn/library/office/dd633687(v=exchg.80)。 aspx –