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: Mailbox names are not quoted
Type: behavior Stage: patch review
Components: email, Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6, Python 3.4, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: barry, bearbin, joebauer, maciej.szulik, mcepl, r.david.murray
Priority: normal Keywords: patch

Created on 2012-02-04 12:04 by joebauer, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
issue13940.patch maciej.szulik, 2015-11-13 23:11 review
Pull Requests
URL Status Linked Edit
PR 6395 open bearbin, 2018-04-06 09:38
Messages (8)
msg152612 - (view) Author: Johannes Bauer (joebauer) Date: 2012-02-04 12:04
imaplib does not qupote mailbox names when it's sending it's query to the server in response to a status request, for example. This will lead to very strange errors if mailboxes are accessed which contain spaces:

i.e.

connection.status("mailbox name", "(MESSAGES)")

will return

  File "/home/joe/test/imaplib.py", line 920, in _command_complete
    raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: STATUS command error: BAD [b'Error in IMAP command STATUS: Status items must be list.']

which indicates that the error is within the actual flag list. It is not, however:

connection.status("\"mailbox name\"", "(MESSAGES)")

works as expected. This may arguably be or not be a bug -- however it is REALLY confusing to the user. Maybe at least a note should be included somewhere that -- just to be safe -- mailbox names should be quoted.

All the best,
Joe
msg222160 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-03 08:38
@Joe sorry for the delay in getting back to you.

@David is this within your remit?
msg222175 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-07-03 13:14
Yes.  It will be necessary to check the RFC to figure out what should be done here.
msg241131 - (view) Author: Maciej Szulik (maciej.szulik) * (Python triager) Date: 2015-04-15 16:48
Joe is correct, according to the spec the names containing special chars (atom-specials) require names to be quoted (https://tools.ietf.org/html/rfc3501#section-5.1): 

   1)    Any character which is one of the atom-specials (see the Formal
         Syntax) will require that the mailbox name be represented as a
         quoted string or literal.

I'll be working on a patch for that.
msg254418 - (view) Author: Maciej Szulik (maciej.szulik) * (Python triager) Date: 2015-11-09 22:35
Currently working on a patch for this.
msg254634 - (view) Author: Maciej Szulik (maciej.szulik) * (Python triager) Date: 2015-11-13 23:11
From imaplib.IMAP4 class description we're stating to quote parameters if necessary. This patch adds that capability according to https://tools.ietf.org/html/rfc3501#section-5.1
msg256127 - (view) Author: Maciej Szulik (maciej.szulik) * (Python triager) Date: 2015-12-08 20:37
siemer thx for the comments in the review. I'll try to address them by the end of this week.
msg315084 - (view) Author: Alexander Harkness (bearbin) * Date: 2018-04-08 13:19
Pull Request opened on GH to fix this issue: https://github.com/python/cpython/pull/6395
History
Date User Action Args
2022-04-11 14:57:26adminsetgithub: 58148
2018-04-21 08:57:32mceplsetnosy: + mcepl
2018-04-08 13:19:13bearbinsetmessages: + msg315084
versions: + Python 3.6, Python 3.7, Python 3.8
2018-04-06 22:36:41BreamoreBoysetnosy: - BreamoreBoy
2018-04-06 09:44:22bearbinsetnosy: + bearbin
2018-04-06 09:38:48bearbinsetstage: patch review
pull_requests: + pull_request6103
2015-12-08 20:37:45maciej.szuliksetmessages: + msg256127
2015-11-13 23:11:53maciej.szuliksetfiles: + issue13940.patch
keywords: + patch
messages: + msg254634
2015-11-09 22:35:30maciej.szuliksetmessages: + msg254418
2015-04-15 16:48:14maciej.szuliksetnosy: + maciej.szulik
messages: + msg241131
2014-07-03 13:14:45r.david.murraysetnosy: + barry
messages: + msg222175
components: + email
2014-07-03 08:38:29BreamoreBoysetnosy: + r.david.murray, BreamoreBoy

messages: + msg222160
versions: + Python 3.4, Python 3.5, - Python 3.1
2012-02-04 12:04:57joebauercreate