
A Conversation Thread is a series of replies that share a common topic. Email clients can display these threads hierarchically or chronologically. To show a thread, applications identify message replies using standard email file formats. Conversation threads help readers see the overall structure, highlight key points, and analyze important information.
In this article we use Aspose.Email’s PST/MAPI features to find and group messages by conversation. We will walk through sample code that traverses a folder, groups messages by conversation, and saves each conversation to its own directory.
- MAPI Properties that are used to Support the Conversation Thread
- C# .NET API to Read Outlook PST Files
- Group messages in PST by conversation thread
MAPI Properties that are used to Support the Conversation Thread
Messages in a PST are stored as MAPI properties. The properties needed to track replies are described in the Microsoft Docs section. The PidTagConversationIndex property identifies whether a message belongs to a specific conversation and indicates its position within the thread. The first 22 bytes of this property act as a header that determines thread membership. See the full details on the property page.
C# .NET API to Read Outlook PST Files
To read PST files we use Aspose.Email for .NET, a powerful library for email processing in .NET. Install it via NuGet or download the DLL.
PM> Install-Package Aspose.Email
Group messages in PST by conversation thread
To group PST messages by conversation we will:
- Create a
ConversationThreadclass to hold messages belonging to the same thread. - Implement a method that searches and groups messages using the conversation index.
- Add a method that saves each conversation to a separate folder.
Create a ConversationThread class
The class contains:
Id: string representation of the 22‑byte conversation index header.Messages: list of message IDs that belong to the thread.
Create a method for searching and grouping messages by conversation
The method works as follows:
- Iterate through all messages in the folder. For speed, read only the message identifier with EnumerateMessagesEntryId.
- Extract the
PidTagConversationIndexproperty using ExtractProperty. - Group messages that share the same first 22 bytes of the index into a single
ConversationThread. - Return a list of
ConversationThreadobjects.
Create a method to save the conversation thread to a separate directory
For each ConversationThread:
- Create a folder named after the thread topic.
- Loop through
ConversationThread.Messages, extract each message with ExtractMessage, and save it using the Save method.
Get a Free API License
Use Aspose.Email for .NET without evaluation limits by obtaining a free temporary license.
Conclusion
This guide demonstrates how to use Aspose.Email to locate and group conversation‑related messages in a PST file. By exploring the PidTagConversationIndex documentation further, you can add features such as hierarchical sorting. Learn more about Aspose.Email in the documentation or ask questions on our forum.