问题
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: <c0f07c940909151905w1ad93fabx19cf595f653c8b@mail.gmail.com>
Message-ID: <9cd2f5ff0909151911r30ddb805n5172970dffc872c2@mail.gmail.com>
I cannot figure out how to efficiently get the replied-to message. The current way:
target = <c0f07c940909151905w1ad93fabx19cf595f653c8b@mail.gmail.com>
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.
回答1:
Apparently, the correct way to do this is:
imap.search ["HEADER", "MESSAGE-ID", target]
来源:https://stackoverflow.com/questions/1430866/gmail-threading-imap-and-ruby