Tuesday, July 29, 2008

Outlook Programming: how to find the parent message for a reply or forward message.

I'm currently involved in developing Outlook add-in. During that I've faced the problem how to find the parent message for a reply or forward message. The idea is that all messages in a conversation have the same ConversationTopic value, while the ConversationIndex is increased by 5 bytes with each change. Here is the sample that uses a MailItem named lastMailItem and searches the Inbox for a matching parent item.


MAPIFolder inbox = m_applicationObject.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
Items inboxItems = inbox.Items.Restrict("[ConversationTopic] = " + "\"" + m_lastMailItem.ConversationTopic + "\"");

string str = m_lastMailItem.ConversationIndex;
string convIndex = str.Substring(0, str.Length - 10);
foreach (MailItem item in inboxItems)
{
if (item.ConversationIndex == convIndex)
{
// Item is found, add your code here!!
break;
}
}

Hope this will help you lot's.

No comments: