imaplib.select on big inbox: Too many arguments fo

2019-04-11 13:28发布

I am trying to access to my emails in Gmail from a python script. The code I use is the following:

import imaplib
m = imaplib.IMAP4_SSL("imap.gmail.com")
m.login("username","password")
m.select("[Gmail]/All Mail")

When running this code in python 2, it works fine, I get the list of all my emails. In python 3 hoverer it fails with the error

>>> m.select("[Gmail]/All Mail")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.2/imaplib.py", line 674, in select
    typ, dat = self._simple_command(name, mailbox)
  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: SELECT command error: BAD [b'[CLIENTBUG] Too many arguments for command']

I have done a bit of testing. It works fine on other folder such as "Inbox" where I get only 400 emails (vs 6000 in "All Mail").

Is it a problem related to the size of the list ? Why is it different in python 2 and 3 ?

Thank you

1条回答
姐就是有狂的资本
2楼-- · 2019-04-11 14:27

Try using m.select('"[Gmail]/All Mail"'), so that the double quotes get transmitted.

I suspect imaplib is not properly quoting the string, so the server gets what looks like two arguments: [Gmail]/All and Mail.

查看更多
登录 后发表回答