使用Python imaplib进行事前/事后搜索 [英] SEARCH BEFORE/AFTER with Pythons imaplib

查看:138
本文介绍了使用Python imaplib进行事前/事后搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个较小的IMAP脚本,写在Python(3.2)上。

I have a smaller IMAP-script written i Python(3.2).

我的搜索行如下:

typ, data = M.search(None, 'FROM', '"MyName"')

我得到了预期的结果。但是,如果我将其更改为:

I get the expected results. However, if I change it to something like:

typ, data = M.search(None, 'AFTER', '"01-Jan-2010"')

(带有或不带有引用日期,我都会收到此错误

(with or without quoted date, I get this error

Traceback (most recent call last):
  File "./priv/imap.py", line 100, in <module>
    main()
  File "./priv/imap.py", line 93, in main
    print(to_json(fetch_result(M, args), args))
  File "./priv/imap.py", line 51, in fetch_result
    typ, data = M.search(None, 'AFTER', '"01-Jan-2010"')
  File "/usr/lib/python3.2/imaplib.py", line 652, in search
    typ, dat = self._simple_command(name, *criteria)
  File "/usr/lib/python3.2/imaplib.py", line 1121, in _simple_command
    return self._command_complete(name, self._command(name, *args))
  File "/usr/lib/python3.2/imaplib.py", line 957, in _command_complete
    raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: SEARCH command error: BAD [b'Could not parse command']

我不知道为什么会这样是非法的,但所有帮助将不胜感激!另外,我最终想要做的是使用 YOUNGER 1234567来进行一些更精细的过滤,但是我不确定gmail / python是否支持此功能。

I have no idea why that would be illegal, but all help will be appreciated! Also, what I ultimatly want to do is use "YOUNGER 1234567" in order to do some finer filtering, but I'm not sure if gmail/python supports this yet.

预先感谢

推荐答案

您可以使用以下搜索:

但是似乎它不支持详细的时间,仅支持日期。

But seems it does not support detailed time, but only date.

并且日期是电子邮件的内部日期(不考虑时间和时区)

and the date is the internal date (disregarding time and timezone) of the email

M.search(None, '(SINCE "01-Jan-2012")')
M.search(None, '(BEFORE "01-Jan-2012")')
M.search(None, '(SINCE "01-Jan-2012" BEFORE "02-Jan-2012")')

这篇关于使用Python imaplib进行事前/事后搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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