Nikitenko Maxim (Sets88)

Personal page

Python - get rid of garbage in your mail

Recently, one of my friends was going to visit exhibition, he requested invite letter, which he got immediately, the only problem is, he got 20 000 copies of it in couple of hour, it was something like that:

He deletes 2000 letters, while he deleted them, he reviced yet another 2000 letters, well, next couple of hours he tried to delete it, he even wrote to support of that site, but it took additional couple of hours to fix their mail service.

Besides, in email box there were important letters, which he could'nt delete (but he told me about that, after i ran script)

So, here were the task:
- Delete every letter from current sender, let's call it spamer@mail.ru

Source code
import imaplib

host = "imap.rambler.ru"
port = "993"
login = "login"
password = "password"

mail = imaplib.IMAP4_SSL(host, port)
mail.login(login, password)
mail.select()
data = mail.search(None, '(FROM "spamer@mail.ru")')[1][0]
for num in data.split() :
    mail.store(num, '+FLAGS', '\\Deleted')
mail.expunge()
mail.close()
mail.logout()
Яндекс.Метрика