Skip to content
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

Merged
merged 6 commits into from
Apr 27, 2020
Merged

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Apr 25, 2020

@corona10
Copy link
Member Author

@ericvsmith
Hi Eric,
I 've implemented the UNSELECT command based on CLOSE command which is already implemented.

I've checked the command correctly on Gmail server and cyrus.andrew.cmu.edu server.
Please let me know something I missed.

Please take a look :)

Copy link
Member

@ericvsmith ericvsmith left a 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.

Doc/library/imaplib.rst Outdated Show resolved Hide resolved
@corona10
Copy link
Member Author

corona10 commented Apr 25, 2020

@ericvsmith

Thank you for the review, Eric :)

I've updated the documentation and added the test.
Please take a look again!

Copy link
Member

@ericvsmith ericvsmith left a 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.

@corona10
Copy link
Member Author

@vstinner
Before merging this PR, Can you please take a look also?

Doc/library/imaplib.rst Outdated Show resolved Hide resolved
Doc/library/imaplib.rst Outdated Show resolved Hide resolved
Lib/imaplib.py Outdated Show resolved Hide resolved
try:
typ, data = self._simple_command('UNSELECT')
finally:
self.state = 'AUTH'
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Lib/imaplib.py Outdated Show resolved Hide resolved
corona10 and others added 2 commits April 27, 2020 22:48
Co-Authored-By: Victor Stinner <vstinner@python.org>
Copy link
Member

@vstinner vstinner left a 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.

@ericvsmith
Copy link
Member

Thanks, @corona10 and @vstinner!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants