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.

classification
Title: imaplib status command cannot handle folder name containing whitespaces
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: duplicate
Dependencies: Superseder: imaplib: incorrect quoting in commands
View: 917120
Assigned To: Nosy List: bjshan, r.david.murray
Priority: normal Keywords:

Created on 2015-03-16 09:31 by bjshan, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg238188 - (view) Author: bjshan (bjshan) Date: 2015-03-16 09:31
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?
msg238210 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-03-16 15:16
This is a duplicate of a subset of issue 917120.
History
Date User Action Args
2022-04-11 14:58:13adminsetgithub: 67866
2015-03-16 15:16:36r.david.murraysetstatus: open -> closed

superseder: imaplib: incorrect quoting in commands

nosy: + r.david.murray
messages: + msg238210
resolution: duplicate
stage: resolved
2015-03-16 09:31:53bjshancreate