2009-09-16 75 views
8

我正在使用Ruby IMAP庫來獲取GMail對話。 GMail線程對話的方式是通過「Message-ID」和「In-Reply-To」消息標題。例如:GMail線程,IMAP和Ruby

In-Reply-To: <[email protected]> 
Message-ID: <[email protected]> 

我不知道如何有效地獲得答覆的消息。目前的辦法:

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 

這需要很長的時間去做順序這樣,但我不能找出正確的咒語由Message-ID頭搜索,我真的不能找到任何有關這是否可能的證據。

回答

10

顯然,要做到這一點,正確的做法是:

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