[tor-commits] [flashproxy/master] Delete Gmail messages from Trash to really delete them.
dcf at torproject.org
dcf at torproject.org
Thu Oct 4 00:34:59 UTC 2012
Author: David Fifield <david at bamsoftware.com>
Date: Wed Oct 3 11:48:57 2012 -0700
Delete Gmail messages from Trash to really delete them.
After being deleted from INBOX, messages were being "archived" in All
Mail. We can delete them for good by copying them to Trash and then
facilitator/facilitator-email-poller | 33 ++++++++++++++++++++++++++++-----
1 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/facilitator/facilitator-email-poller b/facilitator/facilitator-email-poller
index 3f5c4d8..412b5eb 100755
@@ -239,14 +239,32 @@ def handle_message(msg):
log(u"registering %s" % safe_str(fac.format_addr(client_addr)))
+ typ, data = imap.select("[Gmail]/Trash")
+ imap.store("1:*", "+FLAGS", "\\Deleted")
+# Gmail's IMAP folders are funny: they are not real folders, but actually views
+# of messages having a particular label. INBOX consists of messages having the
+# INBOX label, for example. Deleting a message from a folder just removes its
+# label, but the message itself continues to exist in "[Gmail]/All Mail".
+# To really delete a message, you must copy it to "[Gmail]/Trash" and then
+# delete it from there. Messages in Trash are deleted automatically after 30
+# days, but we do it immediately.
+ # Empty the trash first thing, in case there are messages there from a
+ # previous failed run of this program or something.
- typ, data = imap.select()
+ typ, data = imap.select("[Gmail]/All Mail")
exists = int(data)
for i in range(exists):
- # Grab and delete message 1 on each iteration; remaining messages
- # shift down so the next message we process is also message 1.
+ # 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 is None:
@@ -257,8 +275,13 @@ def imap_loop(imap):
except Exception, e:
log("Error processing message, deleting anyway: %s" % str(e))
- imap.store(1, "+FLAGS", "\\Deleted")
+ 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.
More information about the tor-commits