diff -r 8f85262fbe8a Lib/imaplib.py --- a/Lib/imaplib.py Sun Jul 06 02:24:24 2014 -0400 +++ b/Lib/imaplib.py Wed Jul 16 17:19:49 2014 -0700 @@ -108,7 +108,13 @@ br'"') Literal = re.compile(br'.*{(?P\d+)}$', re.ASCII) MapCRLF = re.compile(br'\r\n|\r|\n') -Response_code = re.compile(br'\[(?P[A-Z-]+)( (?P[^\]]*))?\]') + +""" +We don't exclude the ']' character, even though it violates the RFC. This +is because popular IMAP servers, such as Gmail, allow flags with ']'. Thus, +we are purposefully violating the RFC for backward compatibility reasons. +""" +Response_code = re.compile(br'\[(?P[A-Z-]+)( (?P.*))?\]') Untagged_response = re.compile(br'\* (?P[A-Z-]+)( (?P.*))?') Untagged_status = re.compile( br'\* (?P\d+) (?P[A-Z-]+)( (?P.*))?', re.ASCII)