summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/imaplib.py')
-rw-r--r--Lib/imaplib.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index 4d9df55dc3c..a218ab0716e 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -239,6 +239,14 @@ class IMAP4:
return getattr(self, attr.lower())
raise AttributeError("Unknown IMAP4 command: '%s'" % attr)
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *args):
+ try:
+ self.logout()
+ except OSError:
+ pass
# Overridable methods