Permalink
Browse files

Added Unidle with context.

This will unidle the IMAP connection and re-idle it on exit.
  • Loading branch information...
1 parent 9794723 commit acec56ce3639c11b77997a2370ec4a2507d5d384 @rca committed Mar 5, 2013
Showing with 20 additions and 0 deletions.
  1. +20 −0 imapbot/unidle.py
View
@@ -0,0 +1,20 @@
+"""
+A Context for working with an IMAP connection in an unidle state
+"""
+
+
+class Unidle(object):
+ def __init__(self, mail_reader):
+ self.mail_reader = mail_reader
+
+ self.should_reidle = False
+
+ def __enter__(self):
+ self.should_reidle = self.mail_reader.unidle() is not None
+
+ def __exit__(self, ExceptionCls, exception, traceback):
+ if self.should_reidle:
+ self.mail_reader.idle()
+
+ # don't process exceptions, let upstream do that.
+ return False

0 comments on commit acec56c

Please sign in to comment.