Search Gmail thread id
Gmail provides a thread ID to associate groups of messages in the same manner as in the Gmail web interface.
Retrieval of this thread ID is supported via the X-GM-THRID attribute on the FETCH command.
The thread ID is a 64-bit unsigned integer.
The X-GM-THRID attribute may also be used in the SEARCH command to find the UIDs of messages in a given thread.
// C# version
using (Imap imap = new Imap())
{
imap.ConnectSSL("imap.gmail.com");
imap.UseBestLogin("pat@gmail.com", "password");
// Select 'All Mail' folder
CommonFolders common = new CommonFolders(client.GetFolders());
client.Select(common.AllMail);
long newestMessageUID = imap.GetAll().Last();
var threadId = imap.GetEnvelopeByUID(newestMessageUID).GmailThreadId;
List<long> uids = imap.Search().Where(
Expression.GmailThreadId(threadId));
foreach (MessageInfo info in imap.GetMessageInfoByUID(uids))
{
Console.WriteLine("{0} - {1}",
info.Envelope.GmailThreadId,
info.Envelope.Subject);
}
imap.Close();
}
' VB.NET version
Using imap As New Imap()
imap.ConnectSSL("imap.gmail.com")
imap.UseBestLogin("pat@gmail.com", "password")
' Select 'All Mail' folder
Dim common As New CommonFolders(client.GetFolders())
client.Select(common.AllMail)
Dim newestMessageUID As Long = imap.GetAll().Last()
Dim threadId = imap.GetEnvelopeByUID(newestMessageUID).GmailThreadId
Dim uids As List(Of Long) = imap.Search().Where( _
Expression.GmailThreadId(threadId))
For Each info As MessageInfo In imap.GetMessageInfoByUID(uids)
Console.WriteLine("{0} - {1}", _
info.Envelope.GmailThreadId, _
info.Envelope.Subject)
Next
imap.Close()
End Using
You can learn more about this Gmail IMAP extension here:
code.google.com/apis/gmail/imap/#x-gm-thrid
June 13th, 2015 at 13:06
[…] Search Gmail thread id […]
August 30th, 2015 at 09:29
[…] you can find some more information about how to search by X-GM-THRID and all other Gmail IMAP […]