Skip to content

Instantly share code, notes, and snippets.

@vo
Created September 14, 2010 19:54
Show Gist options
  • Save vo/579658 to your computer and use it in GitHub Desktop.
Save vo/579658 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
# A script to delete all e-mails over IMAP
import imaplib, getpass
host = 'imap.server.com'
port = 993
user = 'user'
def main():
imap_pass = getpass.getpass()
print 'Connecting to %s:%s...' % (host, port)
imap = imaplib.IMAP4_SSL(host, port)
print 'Logging in with %s...' % (user)
imap.login(user, imap_pass)
print 'Switching to INBOX...'
if imap.select('INBOX') == 'NO':
print 'Could not switch to INBOX!'
return
typ, data = imap.search(None, 'ALL')
total = len(data[0].split())
for num in data[0].split():
print 'Setting delete flag on %s/%d...' % (num, total)
imap.store(num, '+FLAGS', '\\Deleted')
print 'Expunging...'
imap.expunge()
imap.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment