From 38684c366364fcd4071534a1de62f728407224d8 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 9 Sep 2014 19:07:49 +0300 Subject: =?UTF-8?q?imaplib.IMAP4=20now=20supports=20the=20context=20manage?= =?UTF-8?q?r=20protocol.=20Original=20patch=20by=20Tarek=20Ziad=C3=A9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/imaplib.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Lib/imaplib.py') diff --git a/Lib/imaplib.py b/Lib/imaplib.py index ad104fe76a..27445dd6c5 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -238,6 +238,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 -- cgit v1.2.1