-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
bpo-40375: Implement imaplib.IMAP4.unselect #19712
Conversation
@ericvsmith I've checked the command correctly on Gmail server and Please take a look :) |
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.
Other than the one documentation nit, the code looks good to me. I'm currently not able to test it against a real server.
I think testes should be added to test_imaplib.py.
Thank you for the review, Eric :) I've updated the documentation and added the test. |
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.
This looks good to me. Thanks!
I'm approving it (not that it's needed), but with the caveat that I haven't actually run the code myself.
@vstinner |
try: | ||
typ, data = self._simple_command('UNSELECT') | ||
finally: | ||
self.state = 'AUTH' |
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 see that you copied this code from the close() command. Is it correct to reset to AUTH state if _simple_command() failed with a socket error or timeout error? I don't think that it's correct to reset to AUTH state. Maybe we should even ensure that the IMAP replied "OK" in typ, since very old server may fail if they don't implement the command.
In case of doubt, I'm ok to leave the code as it it.
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 think it's correct enough to return to AUTH state in all cases.
Although really, I think the entire design of the client trying to track the server state is a design error. The commands should just pass to the server, and if the server thinks the connection isn't in the correct state let it generate an error.
But it's likely not worth changing this. The differences between SELECT and AUTH are small, and if you issued an UNSELECT then I think assuming you'll issue a SELECT command before trying another SELECT-state-only command are pretty high.
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.
As I wrote, I'm fine with leaving the code as it is. Fixing imaplib design can be addressed in a separated PR if someone considers that the design should/can be enhanced.
Co-Authored-By: Victor Stinner <vstinner@python.org>
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.
LGTM. Thanks for the doc updates, it now looks better to me.
https://bugs.python.org/issue40375