Message238188
imaplib status failed if the folder name contains whitespace.
For example,
c = IMAP4_SSL('hostname')
c = login(username, password)
c.status('Drafts', '(MESSAGES)') # would succeed
c.status('Apple Mail To Do', '(MESSAGES)') # would fail, error message is:
imaplib.error: STATUS command error: BAD [b"parse error: wrong character; expected '(' but got 'M'"]
It seems the status method could not properly parse the folder name "Apple Mail To Do", it recognizes only the first word "Apple", then failed when meeting the following word "Mail".
I checked imaplib.py, _command 's definition looks like the cause, but I am not sure:
def _command(self, name, *args):
...
name = bytes(name, 'ASCII')
data = tag + b' ' + name
for arg in args:
if arg is None: continue
if isinstance(arg, str):
arg = bytes(arg, "ASCII")
data = data + b' ' + arg
Work around for this:
Manually add double quote around the folder name, like:
'"' + mailbox_name + '"'
BUT,
while c.status('"Apple Mail To Do"', '(MESSAGES)') worked,
c.status("'Apple Mail To Do'", '(MESSAGES)') failed. Suggesting single and double quote weighs not the same? |
|
Date |
User |
Action |
Args |
2015-03-16 09:31:53 | bjshan | set | recipients:
+ bjshan |
2015-03-16 09:31:53 | bjshan | set | messageid: <1426498313.59.0.493788060886.issue23678@psf.upfronthosting.co.za> |
2015-03-16 09:31:53 | bjshan | link | issue23678 messages |
2015-03-16 09:31:52 | bjshan | create | |
|