Skip to content

Instantly share code, notes, and snippets.

@1player
Created September 7, 2012 10:29
Show Gist options
  • Save 1player/3664979 to your computer and use it in GitHub Desktop.
Save 1player/3664979 to your computer and use it in GitHub Desktop.
Empty a POP3 account
#!/usr/bin/env python
import sys
import getpass
import poplib
if len(sys.argv) != 3:
print("{0} <POP3 host> <username>".format(sys.argv[0]))
sys.exit(1)
HOST = sys.argv[1]
USER = sys.argv[2]
pop = poplib.POP3(HOST)
pop.user(USER)
pop.pass_(getpass.getpass())
unread = [int(x.split()[0]) for x in pop.list()[1]]
unread_count = len(unread)
if unread_count < 1:
print("No messages.")
sys.exit(0)
confirm = input("{0} unread messages will be deleted, are you sure? (y/n) ".format(unread_count))
if confirm != 'y':
print("Aborting.")
sys.exit(0)
print("Deleting...")
for i in unread:
pop.dele(i)
pop.quit()
print("Done.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment