Last active
May 3, 2019 10:33
-
-
Save MonsieurV/c66be0485ac4505f340d35d1b29408f9 to your computer and use it in GitHub Desktop.
This script simply mass delete mails from a mailbox through a POP3 access. May be useful when you want to clear an Inbox of spams & all.
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
""" | |
This script simply mass delete mails from a mailbox | |
through a POP3 access. | |
May be useful when you want to clear an Inbox of spams & all. | |
** CAUTION ** After you have selected the number of messages to delete and pressed | |
Enter, it really does begin to delete the emails in a permanent way. (Without passing by a trash folder) | |
Note: the removal is actual when the script close the POP3 connection | |
with the QUIT command (if you provider correctly implements the POP3 protocol). | |
Written by Yoan Tournade <[email protected]> | |
""" | |
import poplib | |
POP_SERVER_URL = 'pop.empire.org' | |
POP_SERVER_PORT = 995 | |
POP_USER = '[email protected]' | |
POP_PASSWORD = 'I hate you!' | |
popClient = poplib.POP3_SSL(POP_SERVER_URL, port=995) | |
popClient.set_debuglevel(1) | |
print(popClient.user(POP_USER)) | |
print(popClient.pass_(POP_PASSWORD)) | |
try: | |
mailCount = popClient.stat()[0] | |
print('There are {} mails in the inbox'.format(mailCount)) | |
numberToDelete = int(input('How many do you want to delete? ')) | |
print(numberToDelete) | |
# print(popClient.list()[1]) | |
for i in range(1, numberToDelete): | |
popClient.dele(i) | |
print('{} DELE commands passed'.format(numberToDelete)) | |
finally: | |
print('QUIT-ing') | |
popClient.quit() | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment