When you download message info, Gmail provides a thread ID (X-GM-THRID attribute in FETCH command response):
using (Imap imap = new Imap())
{
imap.ConnectSSL("imap.gmail.com");
imap.UseBestLogin("pat@gmail.com", "password");
imap.SelectInbox();
List<long> uids = imap.GetAll();
List<messageInfo> infos = imap.GetMessageInfoByUID(uids);
foreach (MessageInfo info in infos)
{
Console.WriteLine("{0} - {1}",
info.Envelope.GmailThreadId,
info.Envelope.Subject);
}
imap.Close();
}
You can also search for all emails in the specific thread:
List<long> uids = imap.Search().Where(
Expression.GmailThreadId(threadId));