5

We're using EWS to generate some analytics on some of our mailboxes.

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.

I was hoping to be able to use the ConversationId to group items, but that seems to be an Exchange 2010-only feature.

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

My current code for getting thread info looks like this:

private IEnumerable<EmailThread> 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 => 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
        });
    }

I am hoping someone knows of a neat way to efficiently get information on replies that constitute part of a conversation?

Kram
  • 4,099
  • 4
  • 39
  • 60

1 Answers1

3

You can fetch the ConversationId and the ConversationIndex via extended properties:

private static readonly ExtendedPropertyDefinition ConversationIdProperty = new ExtendedPropertyDefinition(0x3013, MapiPropertyType.Binary);
private static readonly ExtendedPropertyDefinition ConversationIndexProperty = new ExtendedPropertyDefinition(0x0071, MapiPropertyType.Binary);

var items = service.FindItems(WellKnownFolderName.Inbox, new ItemView(512) { PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, 
            ConversationIdProperty, ConversationIndexProperty)});

Both are binary properties. Their content is described in great detail here:

[MS-OXOMSG]: E-Mail Object Protocol Specification, section 2.2.1.2 and 2.2.1.3.

The properties themselves are defined in [MS-OXPROPS]: Exchange Server Protocols Master Property List.

Henning Krause
  • 5,302
  • 3
  • 24
  • 37
  • Thanks, but I don't think this is any use as I am on exchange 2007. See [here](http://msdn.microsoft.com/en-us/library/ee158568(v=exchg.80).aspx) - specifically "The computation of the value of the PidTagConversationId property is not supported by Exchange 2003, Exchange 2007, Office Outlook 2003, and Office Outlook 2007" - I would reiterate if not clear - we have Exchange 2007 with Outlook 2010 and (somehow) Outlook is capable of creating a threaded view... presumably without the use of ConversationId – Kram Sep 27 '11 at 14:34
  • Mark, you are right. But it seems that you can derive the PidTagConversationId value: Although the ConversationTopic property is not supported in Exchange 2007, it has the same value as the PidTagNormalizedSubject value (see MS-OXOMSG 2.2.1.5). Section 2.2.1.2 specifies how to dervive the ConversationId from that property. The ConversationIndex is supported by Exchange 2007; so, with this combination you should be able to solve the problem. – Henning Krause Sep 27 '11 at 14:52
  • Thanks... It's useful to know about the ConversationTopic, which will help me work out the messages in the thread. When I ask for PidTagConversationId, it returns null, which is odd, given that it has got the PidTagConversationTopic, so, given 2.2.1.2, should have returned the MD5 hash of that - I guess this is being left for me to do :) – Kram Sep 27 '11 at 15:24