EWS API - how to get only latest message per conversation

Andrew Filippov 1 Reputation point
2020-12-25T11:16:03.317+00:00

Wish a very Merry Christmas for everyone!

I have Outlook addin, that should track some particular threads in user's mailbox.
It has collection of Conversation Ids, and uses FindItem operation for searching related items.

I'm puzzled - how make EWS API returning only the latest message for each conversation?

Currently I'm using EWS request like this:

<m:FindItem Traversal="Shallow">
  <m:ItemShape>
    <t:BaseShape>IdOnly</t:BaseShape>
       ... some props ...
    </m:ItemShape>
    <m:Restriction>
      <t:And>
        <t:Exists>
          /* all tracked messages are flagged with Custom properties */
          <t:ExtendedFieldURI DistinguishedPropertySetId="PublicStrings" PropertyName="cecp-{ADD_IN_ID}" PropertyType="String" />
        </t:Exists>
        <t:Or>
          <t:IsEqualTo>
            <t:FieldURI FieldURI="item:ConversationId"/>
              <t:FieldURIOrConstant>
              <t:Constant Value="{ConversationId}" />
            </t:FieldURIOrConstant>
         </t:IsEqualTo>
          ... thousands or even billions of Conversation ids ...
        </t:Or>
      </t:And>
    </m:Restriction>
    <m:ParentFolderIds>
      <t:DistinguishedFolderId Id="sentitems" />
    </m:ParentFolderIds>
  </m:FindItem>

I also thought about results grouping (using <GroupBy />), but it seems has no possibilities to have just one item per group (I have no idea how to make such request at least)

Thanks.

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,963 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.