Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
bpo-13940: imaplib: All string arguments are now quoted when necessary.#6395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -110,7 +110,7 @@ | ||
| br'"') | ||
| # Literal is no longer used; kept for backward compatibility. | ||
| Literal = re.compile(br'.*{(?P<size>\d+)}$', re.ASCII) | ||
| MapCRLF = re.compile(br'\r\n|\r|\n') | ||
| MapCRLF = re.compile(br'[\r\n]') | ||
| # We no longer exclude the ']' character from the data portion of the response | ||
| # code, even though it violates the RFC. Popular IMAP servers such as Gmail | ||
| # allow flags with ']', and there are programs (including imaplib!) that can | ||
| @@ -128,6 +128,8 @@ | ||
| _Literal = br'.*{(?P<size>\d+)}$' | ||
| _Untagged_status = br'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?' | ||
| _Atom_Specials = re.compile(r'[\x00-\x1F\(\)\{ %\*"\\\]]') | ||
| _Quoted_Invalid = re.compile(r'[\r\n]') | ||
| class IMAP4: | ||
| @@ -144,13 +146,10 @@ class IMAP4: | ||
| All arguments to commands are converted to strings, except for | ||
| AUTHENTICATE, and the last argument to APPEND which is passed as | ||
| an IMAP4 literal. If necessary (the string contains any | ||
| non-printing characters or white-space and isn't enclosed with | ||
| either parentheses or double quotes) each string is quoted. | ||
| However, the 'password' argument to the LOGIN command is always | ||
| quoted. If you want to avoid having an argument string quoted | ||
| (eg: the 'flags' argument to STORE) then enclose the string in | ||
| parentheses (eg: "(\Deleted)"). | ||
| an IMAP4 literal. If necessary, each string is quoted. If you | ||
| want to avoid having an argument string quoted (eg: the 'flags' | ||
| argument to STORE) then enclose the string in parentheses | ||
| (eg: "(\Deleted)"). | ||
| Each command returns a tuple: (type, [data, ...]) where 'type' | ||
| is usually 'OK' or 'NO', and 'data' is either the text from the | ||
| @@ -585,10 +584,8 @@ def login(self, user, password): | ||
| """Identify client using plaintext password. | ||
| (typ, [data]) = <instance>.login(user, password) | ||
| NB: 'password' will be quoted. | ||
| """ | ||
| typ, dat = self._simple_command('LOGIN', user, self._quote(password)) | ||
| typ, dat = self._simple_command('LOGIN', user, password) | ||
| if typ != 'OK': | ||
| raise self.error(dat[-1]) | ||
| self.state = 'AUTH' | ||
| @@ -952,6 +949,12 @@ def _command(self, name, *args): | ||
| for arg in args: | ||
| if arg is None: continue | ||
| if isinstance(arg, str): | ||
| if _Quoted_Invalid.search(arg): | ||
| raise self.error('illegal cr or lf in argument') | ||
| if len(arg) > 2 and [arg[0], arg[-1]] == ['(', ')']: | ||
| arg = arg[1:-1] | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it is removing the brackets, which seems undesirable. Compare with the original _checkquote implementation removed in commit f241afa. | ||
| elif _Atom_Specials.search(arg): | ||
| arg = self._quote(arg) | ||
| arg = bytes(arg, self._encoding) | ||
| data = data + b' ' + arg | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct.
MapCRLFis only used in one line, as far as I can tell, to normalize all line endings:With the new pattern,
b'ab\r\ncd\r\n'is replaced withb'ab\r\n\r\ncd\r\n\r\n'. The old pattern leaves that string unchanged and correctly replacesb'ab\ncd\n'withb'ab\r\ncd\r\n'.Also, that "normalization" seems to be controversial: https://bugs.python.org/issue5430
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out - I guess I should just take out the substitution, and add a test for it, so as to fix bpo5430 as well.