简体   繁体   English

python imaplib mail.search; 没有回复电子邮件

[英]python imaplib mail.search; without reply emails

I'm making a script for searching emails and downloading attachments.我正在制作一个用于搜索电子邮件和下载附件的脚本。 It works well, but I encountered a problem when an email fits the criteria but is a reply to another email.它运行良好,但是当 email 符合标准但又是对另一个 email 的回复时,我遇到了问题。

I want to select only the emails that are no replies.我只想 select 没有回复的电子邮件。

Below is my code.下面是我的代码。

#connect to imap server
mail = imaplib.IMAP4_SSL(imap_url)
mail.login(username, password)

result, data = mail.search(None, '(FROM "email-address" SUBJECT "subject")')

Could I maybe add something to the mail.search line so that it ignores replies?我可以在 mail.search 行中添加一些内容以使其忽略回复吗? I'm actually pretty new to this python module so help would be much appreciated!我实际上对这个 python 模块很陌生,所以非常感谢帮助! Thanks谢谢

Good news.好消息。 Visiting this page IMAP Commands you will find the command you are looking for under SEARCH.访问此页面IMAP 命令,您将在 SEARCH 下找到您要查找的命令。

IMAP flag to search for:要搜索的 IMAP 标志:

ANSWERED
    Messages with the \Answered flag set.

So an example of the RAW search string you need to send is:因此,您需要发送的 RAW 搜索字符串的示例是:

SC01 SEARCH ANSWERED

And with your Python example, probably:以您的 Python 为例,可能:

result, data = mail.search(None, '(ANSWERED)')

Here is another great resource for Python imaplib :这是 Python imaplib的另一个重要资源:

imaplib - IMAP4 client library imaplib - IMAP4 客户端库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM