GMail线程,IMAP和Ruby [英] GMail threading, IMAP and Ruby

查看:120
本文介绍了GMail线程,IMAP和Ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

需要很长时间才能按顺序进行,但我无法弄清楚通过Message-ID标题进行搜索的正确咒语,而且我无法真正找到任何有关这是否可行的证据。

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.

推荐答案

显然,正确的方法是:

Apparently, the correct way to do this is:

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

这篇关于GMail线程,IMAP和Ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆