I started writing a guide to IMAP back when I was working on an email client: <a href="https://github.com/rmccue/griffin/tree/master/docs/imap" rel="nofollow">https://github.com/rmccue/griffin/tree/master/docs/imap</a><p>Pulling large amounts of data for things like threading can be difficult on certain servers; my preferred approach ended up being to pull every ID and thread ID to maintain an in-memory tree. (This was, iirc, partially because Gmail’s implementation was slightly crippled with relation to threading.)<p>(I never finished the guide because I stopped on the project, alas - if IMAP were easier to work with, I might have finished it! And sadly, no JMAP support on Gmail, and the gateway was broken.)