简体   繁体   English

Imap 搜索条件 - imaplib (python)

[英]Imap search criteria - imaplib (python)

I'm using imaplib for python and I came across a strange behavior.我将 imaplib 用于 python 并且遇到了一个奇怪的行为。 I don't really know if this is an imap ou imaplib problem/feature, so I'm hoping anyone can give me some lights.我真的不知道这是否是 imap 或 imaplib 问题/功能,所以我希望任何人都可以给我一些提示。

During my project I do several searchs on my gmail boxes.在我的项目中,我对我的 gmail 盒子进行了几次搜索。 Imagine that I do an imap search with the following criteria:想象一下,我使用以下条件进行 imap 搜索:

((since "date A") (before "date B")) ((从“日期 A”开始)(在“日期 B”之前))

Now, if I have emails since "date A", imap(lib) does the expected thing: returns the emails since "date A" and before "data B".现在,如果我有自“日期 A”以来的电子邮件,imap(lib) 会执行预期的操作:返回自“日期 A”以来和“数据 B”之前的电子邮件。 Lovely.迷人的。 However, if I have NO emails since "date A", imap(lib) simply ignores that and returns all emails before "date B" even they are not since "data A"!但是,如果自“日期 A”以来我没有任何电子邮件,imap(lib) 将简单地忽略它并返回“日期 B”之前的所有电子邮件,即使它们不是自“数据 A”以来!

Is this the expected behavior for imap?这是 imap 的预期行为吗? I don't really think so, it makes no sense at all.我真的不这么认为,这根本没有意义。

I really need the ability to search for any given period and I'm hopping not having to pool the box before every search just to know the last email's date.我真的需要搜索任何给定时间段的能力,而且我希望不必在每次搜索之前都汇集该框以了解最后一封电子邮件的日期。

Any idea?任何想法? Am I missing something here?我在这里错过了什么吗?

M.search(None, '(since "12-Jul-2010" before "12-Jul-2011")')

  SINCE 
     Messages whose internal date (disregarding time and timezone)
     is within or later than the specified date.

  BEFORE 
     Messages whose internal date (disregarding time and timezone)
     is earlier than the specified date.

  make sure that `SINCE < BEFORE`

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

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