pythonpython-3.ximapclient

imapclient date and time inaccurate


I recently started using imapclient in order to fetch emails from my Yahoo! account. The program is relatively simple. It is as follows:

yahoo=imap.IMAPClient('imap.mail.yahoo.com', ssl=True)
yahoo.login('myusername', 'mypassword')# cant tell you my username and password, can I?
yahoo.select_folder('Inbox', readonly=True)
# so far, everything is going fine.
yahoo.search(['ON 1-Nov-2015'])

Here's the problem. I've already received tons of messages on November 1st, and the method returns []. It does not work on any date I try. It's as if the 'ON' search doesn't work at all. So I try another method.

yahoo.search(['SINCE 1-Nov-2015'])

No matter how many times I restart the program, less than the actual amount of email UIDs are returned. So I investigate, and I think this may be the problem:

yahoo.fetch(11636, 'BODY[]')

11636 was an email that has a timestamp 10:20 AM, November 1. Instead, the return value says that it was received at 2:20 AM, November 1. I believe this is the problem.

Maybe I am mistaken, and that is the problem. Maybe I am doing something terribly wrong. Either way, any help or suggestions would be greatly appreciated.


Solution

  • I think ON and SINCE are probably using UTC, whereas the time zone you see in the header is in (some) local time. Try querying according to UTC and see if you get the results you expect.