Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

c# - Implementing Outlook 2010's group by conversation using EWS and Exchange 2007

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...