python / cpython

The Python programming language
https://www.python.org
Other
63.38k stars 30.35k forks source link

imaplib status command cannot handle folder name containing whitespaces #67866

Closed 0797f837-f61c-45c5-baed-2f25e8ee3fb7 closed 9 years ago

0797f837-f61c-45c5-baed-2f25e8ee3fb7 commented 9 years ago
BPO 23678
Nosy @bitdancer
Superseder
  • bpo-917120: imaplib: incorrect quoting in commands
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = created_at = labels = ['type-bug', 'library'] title = 'imaplib status command cannot handle folder name containing whitespaces' updated_at = user = 'https://bugs.python.org/bjshan' ``` bugs.python.org fields: ```python activity = actor = 'r.david.murray' assignee = 'none' closed = True closed_date = closer = 'r.david.murray' components = ['Library (Lib)'] creation = creator = 'bjshan' dependencies = [] files = [] hgrepos = [] issue_num = 23678 keywords = [] message_count = 2.0 messages = ['238188', '238210'] nosy_count = 2.0 nosy_names = ['r.david.murray', 'bjshan'] pr_nums = [] priority = 'normal' resolution = 'duplicate' stage = 'resolved' status = 'closed' superseder = '917120' type = 'behavior' url = 'https://bugs.python.org/issue23678' versions = ['Python 3.4'] ```

    0797f837-f61c-45c5-baed-2f25e8ee3fb7 commented 9 years ago

    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?

    bitdancer commented 9 years ago

    This is a duplicate of a subset of bpo-917120.