I am using the Ruby IMAP library to get a GMail conversation. The way that GMail threads conversations is via "Message-ID" and "In-Reply-To" message headers. For example:
In-Reply-To: <[email protected]>
Message-ID: <[email protected]>
I cannot figure out how to efficiently get the replied-to message. The current way:
target = <[email protected]>
imap.search(["NOT", "DELETED"]).each do |msg_id|
uid = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"].message_id
if uid == target
m = imap.fetch(msg_id, "RFC822")[0].attr["RFC822"]
end
end
It takes a really long time to do it sequentially like that, but I can't figure out the correct incantation to search by the Message-ID header, and I can't really find any evidence as to whether this is possible or not.