Skip to content

bpo-40375: Implement imaplib.IMAP4.unselect#19712

Merged
corona10 merged 6 commits intopython:masterfrom
corona10:bpo-40375
Apr 27, 2020
Merged

bpo-40375: Implement imaplib.IMAP4.unselect#19712
corona10 merged 6 commits intopython:masterfrom
corona10:bpo-40375

Conversation

@corona10
Copy link
Copy Markdown
Member

@corona10 corona10 commented Apr 25, 2020

@corona10
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread Doc/library/imaplib.rst Outdated
@corona10
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

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

Comment thread Doc/library/imaplib.rst Outdated
Comment thread Doc/library/imaplib.rst Outdated
Comment thread Lib/imaplib.py Outdated
Comment thread Lib/imaplib.py
try:
typ, data = self._simple_command('UNSELECT')
finally:
self.state = 'AUTH'
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread Lib/imaplib.py Outdated
corona10 and others added 2 commits April 27, 2020 22:48
Comment thread Lib/imaplib.py
Copy link
Copy Markdown
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
Copy Markdown
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