Imap搜索条件 - imaplib(python) [英] Imap search criteria - imaplib (python)

查看:2981
本文介绍了Imap搜索条件 - imaplib(python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用imaplib for python,并且遇到了一个奇怪的行为。我真的不知道这是一个imap或imaplib问题/功能,所以我希望任何人都可以给我一些灯。



在我的项目中,我做了几个搜索我的Gmail邮箱。想象一下,我使用以下标准进行imap搜索:

((因为日期A)(在日期B之前))



现在,如果我从日期A开始收到电子邮件,则imap(lib)会执行预期的操作:从日期A开始并在数据B之前返回电子邮件。可爱。
然而,如果自日期A以来我没有电子邮件,则imap(lib)会简单地忽略它并在日期B之前返回所有电子邮件,即使它们不是数据A!

这是imap的预期行为吗?我真的不这么认为,这完全没有意义。



我真的需要能够搜索任何给定的时间段,而且我不需要游泳池每一次搜索前的箱子只是为了知道最后一封电子邮件的日期。



有什么想法?我在这里丢失了什么?

解决方案

  M.search(None,'(since 2010年7月12日之前2011年7月12日))')






  SINCE 
其内部日期(不考虑时间和时区)
在指定日期之内或之后的邮件。

之前
其内部日期(不考虑时间和时区)
早于指定日期的邮件。






  make确定`SINCE< BEFORE` 


I'm using imaplib for python and I came across a strange behavior. I don't really know if this is an imap ou imaplib problem/feature, so I'm hoping anyone can give me some lights.

During my project I do several searchs on my gmail boxes. Imagine that I do an imap search with the following criteria:

((since "date A") (before "date 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". 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"!

Is this the expected behavior for 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`

这篇关于Imap搜索条件 - imaplib(python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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