+This code is the driver script for dryrun.py, documented seperately.
+Basically what this script does is sets the IMAP server in IDLE mode so
+as to be notified when a new email arrives. However before doing that,
+it first invokes dryrun_invoke() to check for any existing unprocessed
+Amit Saha < firstname.lastname@example.org>
+Version PoC: 27 August, 2011
+# uses impalib2: https://www.it.usyd.edu.au/~piers/python/imaplib2
+# Global configs for the mailbox which acts
+# as the receiever for code execution requestions
+IMAP_SERVER = 'imap.gmail.com'
+username = 'your username'
+password = 'your password'
+# This is the threading object that does all the waiting on
+ def __init__(self, conn):
+ self.thread = Thread(target=self.idle)
+ # This is a neat trick to make thread end. Took me a
+ # while to figure that one out!
+ # Starting an unending loop here
+ # This is part of the trick to make the loop stop
+ # when the stop() command is given
+ # A callback method that gets called when a new
+ # email arrives. Very basic, but that's good.
+ if not self.event.isSet():
+ # Do the actual idle call. This returns immediately,
+ # since it's asynchronous.
+ # This waits until the event is set. The event is
+ # set by the callback, when the server 'answers'
+ # the idle call and the callback function gets
+ # Because the function sets the needsync variable,
+ # this helps escape the loop without doing
+ # anything if the stop() is called. Kinda neat
+ # The method that gets called when a new email arrives.
+ # Replace it with something better.
+ logging.info('Got a request for processing..')
+# Register a IDLE for the mailbox
+ logging.basicConfig(filename='dryrun.log',level=logging.DEBUG,format='%(asctime)s %(message)s')
+ logging.info('Starting Dryrun...')
+ # Check for any unattended new requests
+ # Register IDLE mode with the IMAP server and
+ M = imaplib2.IMAP4_SSL(IMAP_SERVER)
+ # We need to get out of the AUTH state, so we just select
+ # Start the Idler thread