简体   繁体   English

如何使用Python中的imaplib在给定日期过滤掉多个发件人的电子邮件?

[英]How to I filter out emails from multiple senders on a given date using imaplib in Python?

I am using the imaplib4 search function as of now and calling it multiple times for each email id. 到目前为止,我正在使用imaplib4搜索功能,并为每个电子邮件ID多次调用它。 I tried looking everywhere on the internet to look for a format that would let me specify email ids in OR and a date. 我尝试在互联网上到处寻找一种格式,该格式可以让我在OR中指定电子邮件ID和日期。

As of now this format is working for me but I can only specify one email at a time so I make a call per email id. 到目前为止,这种格式对我来说仍然有效,但是我一次只能指定一封电子邮件,因此每个电子邮件ID都会打一个电话。

(FROM "abc@email.com" (ON "25-Dec-2015")) 

In case I have abc and def both sending me emails on that date, I would like a way to specify it in one call. 万一我有abc和def在那个日期都向我发送电子邮件,我想一种在一个电话中指定它的方法。

If your server is RFC compliant and has a full search implementation you can chain together ORs. 如果您的服务器符合RFC并且具有完整的搜索实现,则可以将OR链接在一起。 A simple search should look something like 一个简单的搜索应该看起来像

ON "25-DEC-2015" OR FROM "abc@email.com" FROM "def@email.com"

OR takes two search predicates. 或采用两个搜索谓词。 If you need to chain them, embed an OR in the other one: 如果需要链接它们,则在另一个对象中嵌入一个OR:

ON "25-DEC-2015" OR FROM "abc@email.com" OR FROM "def@email.com" FROM "ghi@email.com"

Not a very nice syntax, and it probably won't work beyond a handful of addresses. 这不是一个很好的语法,它可能无法在少数几个地址之外起作用。 Probably won't work on 'off-brand' IMAP servers. 可能不适用于“非品牌” IMAP服务器。

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

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