问题描述
我正在使用ruby的Net :: IMAP对象,并且可以使用以下任一方法检索一组电子邮件:
I am using ruby's Net::IMAP object and I can retrieve a set of emails using either:
IMAP.all ..args..
或
IMAP.find ..args..
但是仍然存在最好通过例如message-id标头来检索特定电子邮件?
But is there anyway of retrieving a specific email, preferably by the message-id header for example?
这是否可能,或者我是否仅限于全部
和查找
并尝试使用更好的参数来缩小结果集?
Is this possible or am I limited to all
and find
and trying to narrow the result set with better arguments?
推荐答案
我不了解您在IMAP中使用什么技术。但是,提供了按各种字段(包括电子邮件标题)进行搜索的功能。您可以使用以下IMAP命令来检索具有Message-Id < [email protected]>
的电子邮件的UID:
I didn't understand what technology you're using with IMAP. However the IMAP Specification provides the ability to search by a variety of fields, including email headers. You can use the following IMAP command to retrieve the UID of an email with Message-Id <[email protected]>
:
0005 UID SEARCH HEADER Message-ID <[email protected]>
然后,您将获得如下响应:
This will then give you a response such as the following:
* SEARCH 1
0005 OK UID completed
在我的情况下,具有Message-Id < [email protected]>
的电子邮件是第一封电子邮件,因此SEARCH命令返回了匹配的UID的 1
。
In my case the email with Message-Id <[email protected]>
was the first one, so the SEARCH command returned a matching UID of 1
.
然后您可以使用 UID FETCH $检索消息。 c $ c>命令,例如:
You can then retrieve the message using a UID FETCH
command, such as the following:
0006 UID FETCH 1 BODY[]
当然,如果您事先知道UID,则可以跳过 UID搜索
步骤,但这取决于您的应用程序。
Naturally, if you know the UID in advance, you can skip the UID SEARCH
step, but that depends on your application.
这篇关于通过message_id从imap检索一封电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!