1
votes

I am query email messages in a mailbox using EWS. I get a list of email messages back. I want to know how can I tell if a email message is a reply to an earlier email in the mailbox? Basically i want to group the emails like the 'view as conversation' view in Outlook. How can I link the email messages like that?

Thank you.

1

1 Answers

1
votes

If you using 2010 or later then you can use the Conversation operations in EWS to do that see http://msdn.microsoft.com/en-us/library/office/dn610351(v=exchg.150).aspx

Another method you can use is Grab the Transport Headers from the extedned property and parse out the InReplyTo header eg

        ItemView view = new ItemView(100);
        view.PropertySet = new PropertySet(PropertySet.IdOnly);
        PropertySet PropSet = new PropertySet();
        PropSet.Add(ItemSchema.HasAttachments);
        PropSet.Add(ItemSchema.Body);
        PropSet.Add(ItemSchema.DisplayTo);
        PropSet.Add(ItemSchema.IsDraft);
        PropSet.Add(ItemSchema.DateTimeCreated);
        PropSet.Add(ItemSchema.DateTimeReceived);
        ExtendedPropertyDefinition PR_TRANSPORT_MESSAGE_HEADERS = new ExtendedPropertyDefinition(0x007D, MapiPropertyType.String);
        PropSet.Add(PR_TRANSPORT_MESSAGE_HEADERS);
        FindItemsResults<Item> findResults;
        List<EmailMessage> emails = new List<EmailMessage>();
        do
        {
            findResults = service.FindItems(WellKnownFolderName.Inbox, view);
            if (findResults.Items.Count > 0)
            {
                service.LoadPropertiesForItems(findResults.Items, PropSet);
                foreach (var item in findResults.Items)
                {
                    String Headers = "";
                    if (item.TryGetProperty(PR_TRANSPORT_MESSAGE_HEADERS, out Headers))
                    {
                        Int32 slen = Headers.IndexOf("In-Reply-To:");
                        if (slen > 0)
                        {
                            Int32 elen = Headers.IndexOf("\r\n", (slen + 12));
                            Console.WriteLine("InReponse to : " + Headers.Substring((slen+12),elen-(slen+12)));
                        }

                    }                        
                }
            }
            view.Offset += findResults.Items.Count;
        } while (findResults.MoreAvailable);

Cheers Glen