Last active
October 21, 2017 17:49
-
-
Save nikiink/95f82315a3290e6b474d29dbabbc7dec to your computer and use it in GitHub Desktop.
This file contains 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
#INSERIRE MAIL E PASSWORD ################### | |
mail = "........@......it" | |
password = "........" | |
############################################# | |
server = "mail.it.net" | |
cartella_spam = "Posta indesiderata" | |
import imaplib, sys | |
M = imaplib.IMAP4(server) | |
M.login(mail, password) | |
result, mb_spam = M.select(cartella_spam) | |
if result != 'OK': | |
print "Cartella " + cartella_spam + " non trovata!" | |
sys.exit() | |
result, data = M.search(None, "ALL") | |
if result != 'OK': | |
print "Nessun messaggio trovato!" | |
sys.exit() | |
print ("Eliminazione messaggi...") | |
for id_msg in data[0].split(): | |
result, oggetto = M.fetch(id_msg, '(BODY.PEEK[HEADER.FIELDS (Subject)])') | |
print("Deleting ID: " + id_msg + " [ " + oggetto[0][1] + "]") | |
M.store(id_msg, '+FLAGS', '\\Deleted') | |
print ("Eliminazione OK") | |
print ("Expunging...") | |
M.expunge() | |
print ("Expung OK") | |
M.close() | |
M.logout() |
This file contains 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
#INSERIRE MAIL E PASSWORD ################### | |
mail = "........@......it" | |
password = "........" | |
############################################# | |
server = "mail.it.net" | |
cartella_spam = '"Posta indesiderata"' | |
import imaplib, sys | |
M = imaplib.IMAP4(server) | |
M.login(mail, password) | |
result, mb_spam = M.select(cartella_spam) | |
if result != 'OK': | |
print "Cartella " + cartella_spam + " non trovata!" | |
sys.exit() | |
result, data = M.search(None, "ALL") | |
if result != 'OK': | |
print "Nessun messaggio trovato!" | |
sys.exit() | |
print ("Eliminazione messaggi...") | |
for id_msg in data[0].split(): | |
result, oggetto = M.fetch(id_msg, '(BODY.PEEK[HEADER.FIELDS (Subject)])') | |
print("Deleting ID: %s [%s]" % (bytes.decode(id_msg), oggetto[0][1])) | |
M.store(id_msg, '+FLAGS', '\\Deleted') | |
print ("Eliminazione OK") | |
print ("Expunging...") | |
M.expunge() | |
print ("Expung OK") | |
M.close() | |
M.logout() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lo script elimina il contenuto della cartella posta indesiderata per caselle di posta elettronica gestite da it.net e raggiungibili al link wbs.it.net. Lo script wbs_svuota_spam.py funziona con python 2.7, wbs_svuota_spam_py3.py funziona con la versione 3. È possibile eseguirlo come operazione pianificata eseguendolo con l'utente SYSTEM per esempio all'avvio del pc, oppure con cron su linux.