I want to create a gmail client with the ability to view emails as conversations (threads). In imaplib, there is a method: 
IMAP4.thread(threading_algorithm, charset, search_criterion[, ...])
I think it could be the solution. Anybody has experience using it? Please give an example. Thanks.
As far as i know, Gmail uses an algorithm that is private, and it's not stated in RFCs.

They use a combination of headers (like in-reply-to and references) and considering subject (but in a different way that THREAD=references does).
How to use thread search method in imaplib?