Skip to content

Instantly share code, notes, and snippets.

@ochronus
Last active September 4, 2015 20:41
Show Gist options
  • Save ochronus/7ed5a01042d007024a52 to your computer and use it in GitHub Desktop.
Save ochronus/7ed5a01042d007024a52 to your computer and use it in GitHub Desktop.
Delete messages from flooded labels
import imaplib
EMAIL_ADDRESS = '[email protected]'
PASSWORD = 'nope nope nope'
FOLDER = 'This_is_a_parent_label/this_is_a_sublabel'
while True:
try:
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login(EMAIL_ADDRESS, PASSWORD)
mail.select(FOLDER)
mail.store("1:*", '+X-GM-LABELS', '\\Trash')
mail.expunge()
except imaplib.IMAP4.abort as e:
print "Imap abort, restarting for the rest of the mails: {msg}".format(msg=str(e))
continue
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment