Question
How can I group individual emails by conversation when using the Exchange WebServices API so that I know for sure (100%) that one email is in the same conversation as the other?
By individual I mean: I should be able to download 1 email at a time, since when a late response is sent (let's say as a reply to an email from last month), I don't want to bulk-download the whole conversation again, but just that one email to be able to store it in my own database.
context
I am working on a project where I need to put all fresh emails in a MySQL database so that we can add extra meta data from out of our CRM application. Right now I am doing some prototyping with the Exchange WebServices API over XML so that I know what data is available and what it looks like. I am doing this in PHP (also the language our CRM is built in).
Problem
When running a simple XML request (see below) I receive some emails from my inbox/sentitems folder. Since I know I had a conversation with a colleague to test the ConversationIndex I found out that the ConversationIndex doesn't seem to be an index as I expected it to be. I expected it to be equal on all emails so that I could easily group one conversation together.
But that doesn't appear to be true. Because when I lay the ConversationIndexes of my inbox and snetitems (of one conversation) next to each other I get the following result: (--> sentitem, <-- inbox)
- -->
Ac9IKUBx8yX3vSXYQSWcb8ggCfC7FQ==
(first sentitem) - <--
Ac9IKUBx8yX3vSXYQSWcb8ggCfC7FQAAAT1A
(reply to 1) - -->
Ac9IKUBx8yX3vSXYQSWcb8ggCfC7FQAAAT1AAAAHYQA=
(reply to 2) - <--
Ac9IKUBx8yX3vSXYQSWcb8ggCfC7FQAAAT1AAAAHYQAAAAScMA==
(reply to 3) - -->
Ac9IKUBx8yX3vSXYQSWcb8ggCfC7FQAAAT1AAAAHYQAAAAScMAAACBsQ
(reply to 4) - <--
Ac9IKUBx8yX3vSXYQSWcb8ggCfC7FQAAAT1AAAAHYQAAADX4EA==
(reply to 5) - <--
Ac9IKUBx8yX3vSXYQSWcb8ggCfC7FQAAP7ZQ
(reply to 1)
Example of other conversation ConversationIndex: Ac9IB53hRlE85QAKR9qCJ8pbv8gikwAAtByQ
As you can see the ConversationIndex changes for every email except for the first 30 characters. Another thing I found out by consulting the answer on this question is that I should use a BitConverter and modify the ConverationIndex but that is for C#. I couldn't find a PHP solution for this neither.
Also, I can't find any information on this subject in the EWS docs (for example: http://msdn.microsoft.com/en-us/library/ms528174(v=exchg.10).aspx).
Possible alternatives
I saw a References
key in the XML response from the Exchange server, but using those InternetMessageId
's to determine what conversation an email is in would become a true hell.
Another thing I noticed was the ConversationId
(http://msdn.microsoft.com/en-us/library/ff387041%28v=office.12%29.aspx) but that doesn't seem to be what I'm look for neither.
The XML request, just for reference
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Body>
<FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
Traversal="Shallow">
<ItemShape>
<t:BaseShape>AllProperties</t:BaseShape>
</ItemShape>
<IndexedPageItemView MaxEntriesReturned="5" Offset="0" BasePoint="Beginning" />
<ParentFolderIds>
<t:DistinguishedFolderId Id="inbox OR sentitems"/>
</ParentFolderIds>
</FindItem>
</soap:Body>
</soap:Envelope>
UPDATE 1
It looks like I have to use the ConversationId instead of the index. Although I am working on Exchange 2007 at the moment we are upgrading to 2013 very soon. Can somebody verify that I have to use the ConversationId indeed?