bpo-40375: Implement imaplib.IMAP4.unselect#19712
Conversation
|
@ericvsmith I've checked the command correctly on Gmail server and Please take a look :) |
ericvsmith
left a comment
There was a problem hiding this comment.
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. |
ericvsmith
left a comment
There was a problem hiding this comment.
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.
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.
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.
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 <[email protected]>
vstinner
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the doc updates, it now looks better to me.
https://bugs.python.org/issue40375