nbsamurai
nbsamurai

Reputation: 346

Using mailkit to retrieve email chains, returns only the first email of the conversation

I'm developing an email client using mailkit. I need to display emails as conversations like how it's getting displayed in webmail clients. When I try to fetch data using mailkit for a complete email thread, I'm able to retrieve only the first email of the conversation.

I've checked for ImapCapabilitites.Thread value using mailkit and it returned false. So I'm trying to fetch a email thread which has 3 messages and I get only the first message as output and the children count of the thread object is always zero. Please check the below code and let me know if I'm missing any flags which needs to be passed along

var summaries = targetFolder.Fetch(requestFilter, MessageSummaryItems.Envelope | MessageSummaryItems.Flags | MessageSummaryItems.References); 
var orderBy = new OrderBy[] { OrderBy.ReverseDate };
var threads = MessageThreader.Thread (summaries, ThreadingAlgorithm.References, orderBy);

Where requestFilter is an IList<UniqueId> and targetFolder is the subfolder inside inbox in which the mail thread is stored.

Upvotes: 1

Views: 1923

Answers (1)

jstedfast
jstedfast

Reputation: 38528

In general, you need all of the messages in order to properly thread them.

So your code should look like this:

var summaries = targetFolder.Fetch(0, -1, MessageSummaryItems.UniqueId | MessageSummaryItems.InternalDate | MessageSummaryItems.Envelope | MessageSummaryItems.References); 
var orderBy = new OrderBy[] { OrderBy.ReverseDate };
var threads = MessageThreader.Thread (summaries, ThreadingAlgorithm.References, orderBy);

You also don't need the Flags to thread them, but since you are sorting by Date, it may be beneficial to grab the InternalDate as a fallback in case a message's Date header is not set.

Upvotes: 1

Related Questions