-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
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
Open
bearbin
wants to merge
1
commit into
python:main
Choose a base branch
from
bearbin:fix-issue-13940
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+60
−11
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.