Exchange:使用XML请求在EWS对话中查找项目?

时间:2013-09-25 15:12:11

标签: xml soap exchange-server exchangewebservices

我正在尝试使用Exchange EWS 2010找到对话中的项目,无论他们所在的文件夹。我不想得到所有对话的列表一个文件夹。我想逐个查询对话。

我在Android上这样做,并且已经为其他EWS请求发送了XML soap请求。

我的问题是:

如果给出了ConversationId,那么如何格式化XML以在单个对话中检索项目?

我尝试过使用带有限制的FindItem和一个QueryString,但似乎都没有给出任何结果。

有没有办法这样做?我熟悉“FindConversations”操作,但它似乎返回文件夹中所有会话的所有消息。我想要特定对话的消息。

以下是我尝试过的两个示例XML请求。

尝试使用QueryString:

<?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="Exchange2010_SP1" />
  </soap:Header>
  <soap:Body>
    <m:FindItem Traversal="Shallow">
      <m:ItemShape>
        <t:BaseShape>AllProperties</t:BaseShape>
        <t:AdditionalProperties>
          <t:FieldURI FieldURI="item:Subject" />
          <t:FieldURI FieldURI="item:DateTimeReceived" />
          <t:FieldURI FieldURI="message:From" />
        </t:AdditionalProperties>
      </m:ItemShape>
      <m:IndexedPageItemView MaxEntriesReturned="10" Offset="0" BasePoint="Beginning" />
      <m:ParentFolderIds>
          <t:DistinguishedFolderId Id="inbox"/>
      </m:ParentFolderIds>
      <m:QueryString>item:ConversationId:AAQkADg5MmFjNTViLTYwODUtNGNmYi04MzhjLTczZTdkOTZmYjllNwAQAA/J3OiwUmlBntyd9PhAWBM=</m:QueryString>
    </m:FindItem>
  </soap:Body>
</soap:Envelope>

尝试使用限制:

<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="Exchange2010_SP1" />
  </soap:Header>
  <soap:Body>
    <m:FindItem Traversal="Shallow">
      <m:ItemShape>
        <t:BaseShape>IdOnly</t:BaseShape>
      </m:ItemShape>
      <m:IndexedPageItemView MaxEntriesReturned="50" Offset="0" BasePoint="Beginning" />
      <m:Restriction>
          <t:IsEqualTo>
            <t:FieldURI FieldURI="item:ConversationId" />
            <t:FieldURIOrConstant>
              <t:Constant Value="AAQkADg5MmFjNTViLTYwODUtNGNmYi04MzhjLTczZTdkOTZmYjllNwAQAA/J3OiwUmlBntyd9PhAWBM="/>
            </t:FieldURIOrConstant>
          </t:IsEqualTo>
      </m:Restriction>
      <m:SortOrder>
        <t:FieldOrder Order="Descending">
          <t:FieldURI FieldURI="item:DateTimeReceived" />
        </t:FieldOrder>
      </m:SortOrder>
      <m:ParentFolderIds>
        <t:DistinguishedFolderId Id="inbox" />
      </m:ParentFolderIds>
    </m:FindItem>
  </soap:Body>
</soap:Envelope>

2 个答案:

答案 0 :(得分:4)

我能够根据ConversationIndex搜索邮件。我在Java / Android上使用“JWebServices for Exchange”API。您必须使用带限制的findItem方法并使用PR_CONVERSATION_INDEX字段(标准MAPI属性)。代码就像:

        IsEqualTo restriction = new IsEqualTo(MapiPropertyTag.PR_CONVERSATION_INDEX, "AA3OiwUmlB...");

        FindItemResponse response = service.findItem(StandardFolder.INBOX, restriction);

答案 1 :(得分:2)

这似乎几乎可以工作,但它只返回一个文件夹中的项目....不是所有文件夹; - (

请注意PR_CONVERSATION_INDEX = 0x0071

<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="Exchange2010" />
  </soap:Header>
  <soap:Body>
    <m:FindItem Traversal="Shallow">
      <m:ItemShape>
        <t:BaseShape>IdOnly</t:BaseShape>
        <t:AdditionalProperties>
          <t:FieldURI FieldURI="item:Subject"/>
        </t:AdditionalProperties>
      </m:ItemShape>
      <m:IndexedPageItemView MaxEntriesReturned="5" Offset="0" BasePoint="Beginning"/>
      <m:Restriction>
        <t:Or>
          <t:IsEqualTo>
            <t:ExtendedFieldURI PropertyTag="0x0071" PropertyType="Binary"/>
            <t:FieldURIOrConstant>
              <t:Constant Value="Ac7BH8JjB509L0wAfEakbAl7ATtZhA=="/>
            </t:FieldURIOrConstant>
          </t:IsEqualTo>
          <t:IsEqualTo>
            <t:ExtendedFieldURI PropertyTag="0x0071" PropertyType="Binary"/>
            <t:FieldURIOrConstant>
              <t:Constant Value="AQHOgWGUK7JmFnIm5E6tWXtmj4J2FplmRcIA"/>
            </t:FieldURIOrConstant>
          </t:IsEqualTo>
          <t:IsEqualTo>
            <t:ExtendedFieldURI PropertyTag="0x0071" PropertyType="Binary"/>
            <t:FieldURIOrConstant>
              <t:Constant Value="AQHOcazuyUKjqFgn8Eq0mqIHnczJhplGdo5DgABT/gA="/>
            </t:FieldURIOrConstant>
          </t:IsEqualTo>
        </t:Or>
      </m:Restriction>
      <m:ParentFolderIds>
        <t:DistinguishedFolderId Id="inbox"/>
      </m:ParentFolderIds>
    </m:FindItem>
  </soap:Body>
</soap:Envelope>