title: Implementing Outlook 2010's group by conversation using EWS and Exchange 2007
body: <p>We're using EWS to generate some analytics on some of our mailboxes. </p>
  
  <p>Part of this is getting a count/name/start/end of conversations. A conversation being analogous to the way Outlook 2010 shows them when grouping by conversation.</p>
  
  <p>I was hoping to be able to use the ConversationId to group items, but that seems to be an Exchange 2010-only feature.</p>
  
  <p>I can group by subject within a folder to get a simple idea of threads... however this does not handle split conversations, as Outlook 2010 does - specifically, it doesn't handle bringing in the replies that are in the sent items (these are important to us - we can't get good metrics without also looking at replies).</p>
  
  <p>My current code for getting thread info looks like this:</p>
  
  <pre><code>private IEnumerable&lt;EmailThread&gt; GetThreads(Folder folder)
      {
          var view = new ItemView(int.MaxValue) {PropertySet = new PropertySet(BasePropertySet.IdOnly)};
  
          // view.PropertySet.Add(ItemSchema.ConversationId); - Can't use this as we're stuck on Exchange 2007 !!!
          view.PropertySet.Add(ItemSchema.Subject);
          view.PropertySet.Add(ItemSchema.DateTimeReceived);
  
          var grouping = new Grouping(ItemSchema.Subject, SortDirection.Descending, ItemSchema.DateTimeReceived, AggregateType.Maximum);
          var groupResults = folder.FindItems(view, grouping);
  
  
          return groupResults.Select(x =&gt; new EmailThread
          {
              Name = x.Items.First().Subject,
              Items =  x.Items.Count,
              StartDate = x.Items.Last().DateTimeReceived, // Assume last in thread is first email
              EndDate = x.Items.First().DateTimeReceived // Assume first in thread is most recent
          });
      }
  </code></pre>
  
  <p>I am hoping someone knows of a neat way to efficiently get information on replies that constitute part of a conversation?</p>