-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
bpo-40375: Implement imaplib.IMAP4.unselect #19712
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
Changes from all commits
0619626
8889abe
e6c36ff
3f229db
81f9244
7c3f09b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,7 @@ | |
| 'THREAD': ('SELECTED',), | ||
| 'UID': ('SELECTED',), | ||
| 'UNSUBSCRIBE': ('AUTH', 'SELECTED'), | ||
| 'UNSELECT': ('SELECTED',), | ||
| } | ||
|
|
||
| # Patterns to match server responses | ||
|
|
@@ -902,6 +903,22 @@ def unsubscribe(self, mailbox): | |
| return self._simple_command('UNSUBSCRIBE', mailbox) | ||
|
|
||
|
|
||
| def unselect(self): | ||
| """Free server's resources associated with the selected mailbox | ||
| and returns the server to the authenticated state. | ||
| This command performs the same actions as CLOSE, except | ||
| that no messages are permanently removed from the currently | ||
| selected mailbox. | ||
|
|
||
| (typ, [data]) = <instance>.unselect() | ||
| """ | ||
| try: | ||
| typ, data = self._simple_command('UNSELECT') | ||
| finally: | ||
| self.state = 'AUTH' | ||
|
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. 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.
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. 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.
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. 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. |
||
| return typ, data | ||
|
|
||
|
|
||
| def xatom(self, name, *args): | ||
| """Allow simple extension commands | ||
| notified by server in CAPABILITY response. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| :meth:`imaplib.IMAP4.unselect` is added. Patch by Dong-hee Na. |
Uh oh!
There was an error while loading. Please reload this page.