GMail线程,IMAP和Ruby

我正在使用Ruby IMAP库来获得GMail对话。 GMail线程对话的方式是通过“Message-ID”和“In-Reply-To”消息头。 例如:

In-Reply-To:  Message-ID:  

我无法弄清楚如何有效地获取回复消息。 目前的方式:

 target =  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 

像这样顺序执行它需要很长时间,但我无法找出通过Message-ID标头搜索的正确咒语,而且我无法找到任何关于这是否可能的证据。

显然,正确的方法是:

 imap.search ["HEADER", "MESSAGE-ID", target]