charlierguo / gmail

A Pythonic interface for Google Mail
MIT License
1.77k stars 386 forks source link

Error when fetching inbox with no unread emails with unread=True, prefetch=True #61

Open benbaptist opened 9 years ago

benbaptist commented 9 years ago

When trying to fetch for new emails with .mail(unread=True, prefetch=True) when there's no unread emails, this error is thrown. It does not appear if I don't pass unread or prefetch, but together, it happens.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/gmail/mailbox.py", line 64, in mail
    self.messages.update(self.gmail.fetch_multiple_messages(messages_dict))
  File "/usr/local/lib/python2.7/dist-packages/gmail/gmail.py", line 145, in fetch_multiple_messages
    response, results = self.imap.uid('FETCH', fetch_str, '(BODY.PEEK[] FLAGS X-GM-THRID X-GM-MSGID X-GM-LABELS)')
  File "/usr/lib/python2.7/imaplib.py", line 772, in uid
    typ, dat = self._simple_command(name, command, *args)
  File "/usr/lib/python2.7/imaplib.py", line 1087, in _simple_command
    return self._command_complete(name, self._command(name, *args))
  File "/usr/lib/python2.7/imaplib.py", line 917, in _command_complete
    raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: UID command error: BAD ['Could not parse command']

Sample code:

g = gmail.login("user", "pass")
inbox = g.inbox()
mail = inbox.mail(unread=True, prefetch=True)

I'm not 100% sure if this is a problem on my end/something I'm doing wrong, or on the module's end. Hopefully it is easily fixable!

johnmaguire commented 8 years ago

I couldn't get unread=True to work, so I used query="is:unread" and then got the error described in this issue.