Skip to content

Instantly share code, notes, and snippets.

@Roadmaster
Created July 19, 2016 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Roadmaster/94b89a32b40c8ef5ab469c9de056e274 to your computer and use it in GitHub Desktop.
Save Roadmaster/94b89a32b40c8ef5ab469c9de056e274 to your computer and use it in GitHub Desktop.
# This script will log into the specified IMAP server, select the INBOX,
# then just delete all the messages present there.
import imaplib
the_imap = imaplib.IMAP4_SSL("your-imap-server.com")
print(the_imap.login("your-login", "your-plaintext-password"))
print(the_imap.list())
print(the_imap.select("INBOX"))
typ, data = the_imap.search(None, "ALL")
msg_set = data[0].split()
if msg_set:
msg_set_str = "%s:%s" % (msg_set[0], msg_set[-1])
the_imap.store(msg_set_str, '+FLAGS', '\\Deleted')
the_imap.expunge()
print(the_imap.select("INBOX"))
the_imap.close()
the_imap.logout()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment