开发者

SEARCH BEFORE/AFTER with Pythons imaplib

开发者 https://www.devze.com 2023-02-24 00:02 出处:网络
I have a smalle开发者_如何学Gor IMAP-script written i Python(3.2). I my search-line looks like this:

I have a smalle开发者_如何学Gor IMAP-script written i Python(3.2).

I my search-line looks like this:

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']

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.

thanks in advance


You can use search like these:

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")')


you can try:

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

or if you're using UIDs:

typ, data = M.uid('search', '(SINCE 01-Jan-2010)')
0

精彩评论

暂无评论...
验证码 换一张
取 消