[tor-commits] [flashproxy/master] Just read and delete the first IMAP message until we get an error.

dcf at torproject.org dcf at torproject.org
Thu Oct 4 00:34:59 UTC 2012


commit 31033ccfd21cd8c1aff7ae5934ddd9da9e6913da
Author: David Fifield <david at bamsoftware.com>
Date:   Wed Oct 3 11:58:12 2012 -0700

    Just read and delete the first IMAP message until we get an error.
    
    We used EXISTS as a hint to how many messages there will be to process,
    but this number can change during the loop execution, so we have to
    check for an error anyway, so we may as well use that as our exit
    condition.
---
 facilitator/facilitator-email-poller |   41 +++++++++++++++++----------------
 1 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/facilitator/facilitator-email-poller b/facilitator/facilitator-email-poller
index 412b5eb..cfae523 100755
--- a/facilitator/facilitator-email-poller
+++ b/facilitator/facilitator-email-poller
@@ -262,26 +262,27 @@ def imap_loop(imap):
         typ, data = imap.select("[Gmail]/All Mail")
         exists = int(data[0])
 
-        for i in range(exists):
-            # Grab message 1 on each iteration; remaining messages shift down so
-            # the next message we process is also message 1.
-            typ, data = imap.fetch(1, "(BODY[])")
-            if data[0] is None:
-                break
-
-            try:
-                msg = email.message_from_string(data[0][1])
-                handle_message(msg)
-            except Exception, e:
-                log("Error processing message, deleting anyway: %s" % str(e))
-
-            imap.copy(1, "[Gmail]/Trash")
-            # Attempting to delete from All Mail here would have no effect.
-            # Messages disappear from All Mail when they are deleted from Trash
-            # in the next step.
-
-        # Now delete all messages from Trash to really delete them.
-        imap_empty_trash(imap)
+        if exists > 0:
+            while True:
+                # Grab message 1 on each iteration; remaining messages shift down so
+                # the next message we process is also message 1.
+                typ, data = imap.fetch(1, "(BODY[])")
+                if data[0] is None:
+                    break
+
+                try:
+                    msg = email.message_from_string(data[0][1])
+                    handle_message(msg)
+                except Exception, e:
+                    log("Error processing message, deleting anyway: %s" % str(e))
+
+                imap.copy(1, "[Gmail]/Trash")
+                # Attempting to delete from All Mail here would have no effect.
+                # Messages disappear from All Mail when they are deleted from Trash
+                # in the next step.
+
+            # Now delete all messages from Trash to really delete them.
+            imap_empty_trash(imap)
 
         time.sleep(POLL_INTERVAL)
 





More information about the tor-commits mailing list