refonte : theme->topic et home.pt

This commit is contained in:
2021-09-11 09:40:52 +02:00
parent d24becec1c
commit e8542c9b66
11 changed files with 100 additions and 76 deletions

View File

@@ -3,25 +3,48 @@
# Compter les emails BEFORE DATE
#
from pprint import pprint
import datetime
import imaplib
# connecter au serveur IMAP de la societe
mbx_name = 'ctphuoc@gmail.com'
mbx_pwd = 'ztwciswzhxxogcfv'
# connecter au serveur IMAP
conn = imaplib.IMAP4_SSL('imap.gmail.com')
conn.login('ctphuoc@gmail.com', 'ztwciswzhxxogcfv')
conn.login(mbx_name, mbx_pwd)
# select INBOX
# lister les dossiers
typ, data = conn.list()
print('Liste des dossiers :')
pprint(data)
# delete mails before 14 years
before_date = (datetime.date.today() - datetime.timedelta(5110)).strftime("%d-%b-%Y")
print("Delete emails before " + before_date)
# select ALL
conn.select('INBOX')
rv, data = conn.search(None, 'BEFORE "01-FEB-2006"')
messages = data[0].split(b' ')
for mail in messages:
# mark the mail as deleted
conn.store(mail, "+FLAGS", "\\Deleted")
print(str(mail) + " supprimé")
# delete all the selected messages
conn.expunge()
rv, data = conn.search(None, '(BEFORE {0})'.format(before_date))
nb_mails = str(len(data[0]))
print(nb_mails + " emails founded")
resp = input ("Enter 'c' to continue, or 'a' to abort : ")
if resp=="c":
print("Moving " + nb_mails + " emails to Trash")
messages = data[0].split(b' ')
for mail in messages:
# move to trash
conn.store(mail, '+X-GM-LABELS', '\\Trash')
#This block empties trash, remove if you want to keep, Gmail auto purges trash after 30 days.
print("Emptying Trash & Expunge...")
conn.select('[Gmail]/Corbeille')
conn.store("1:*", '+FLAGS', '\\Deleted')
# delete all the selected messages
conn.expunge()
print("Script completed")
else:
print("Script aborted")
# deconnexion du serveur
conn.close()
conn.logout()