Created
September 14, 2010 19:54
-
-
Save vo/579658 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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