I really don't know enough about IMAP to be doing all this, but I just fumbled my way through adding support for X-GM-THRID based on the X-GM-MSGID extension: https://github.com/alltom/libetpan/commit/0b1907c3850562ab5e76099bb1987f076e298fc9

It seems to work when I use it like this: https://github.com/alltom/MailCore/blob/master/Source/CTCoreMessage.m#L681 (I expected the data to be in `fetch_result`, but stepping through the code showed me otherwise.)