Python IMAP4 select mailbox name contain space character, error

余生颓废 提交于 2020-01-03 02:00:15

问题


I am using Python imaplib.IMAP4 to connect to Google email. Every thing is okay except when I use IMAP4.select() method using a mailbox name that contains a space character. Let's say my mailbox name is "Gama Sutra".

When I execute imap.select('[Gmail]/Gama Sutra') it gives me this error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imaplib.py", line 682, in select
typ, dat = self._simple_command(name, mailbox)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imaplib.py", line 1133, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imaplib.py", line 964, in _command_complete
raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: SELECT command error: BAD [b'Could not parse command']

How do I address that?


回答1:


It should do this automatically, but simply surround your folder name in double quotes:

imap.select('"[Gmail]/Gama Sutra"')



来源:https://stackoverflow.com/questions/33684770/python-imap4-select-mailbox-name-contain-space-character-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!