+2 votes

I am trying to create a browser extension for gmail which returns thread id's - 153cc168f2424284

Is this searchable using the messageID search in the library?

Is there a way to get messageID from the extension if not?

by

1 Answer

0 votes
 
Best answer

“153cc168f2424284” is the Gmail thread-ID in hex. Use Convert.ToInt64 to parse it:

decimal threadID = Convert.ToInt64("153cc168f2424284", 16);

Then you can use Imap.Search method along with Expression.GmailThreadId to find all messages in this thread:

List<long> uids = imap.Search(Expression.GmailThreadId(threadID));

Entire code:

decimal threadID = Convert.ToInt64("153cc168f2424284", 16);

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");        
    imap.UseBestLogin("user@gmail.com", "password");

    imap.SelectInbox();

    List<long> uids = imap.Search(Expression.GmailThreadId(threadID));

    // now download each message and display the subject
    foreach (long uid in uids)
    {
        IMail message = new MailBuilder()
            .CreateFromEml(imap.GetMessageByUID(uid));
        Console.WriteLine(message.Subject);
    }

    imap.Close();
}
by (301k points)
...