This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bjshan
Recipients bjshan
Date 2015-03-16.09:31:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1426498313.59.0.493788060886.issue23678@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2015-03-16 09:31:53bjshansetrecipients: + bjshan
2015-03-16 09:31:53bjshansetmessageid: <1426498313.59.0.493788060886.issue23678@psf.upfronthosting.co.za>
2015-03-16 09:31:53bjshanlinkissue23678 messages
2015-03-16 09:31:52bjshancreate