Email plein ecran avec suggestions d'adresses precedentes
- Formulaire email : overlay fullscreen au lieu d'inline (debordait de l'ecran) - Historique emails : stocke chaque adresse dans data/emails_history.json - Suggestions : affiche les emails deja saisis en pills cliquables, filtrees au fur et a mesure de la saisie - API GET /api/emails/historique + DELETE pour reset Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
import logging
|
||||
import smtplib
|
||||
from email.mime.base import MIMEBase
|
||||
@@ -6,7 +7,7 @@ from email.mime.text import MIMEText
|
||||
from email import encoders
|
||||
from pathlib import Path
|
||||
|
||||
from backend.config import charger_config
|
||||
from backend.config import charger_config, RACINE
|
||||
|
||||
log = logging.getLogger("photobooth.mailer")
|
||||
|
||||
@@ -58,7 +59,38 @@ def envoyer_photo(destinataire: str, chemin_photo: Path) -> bool:
|
||||
serveur.login(smtp_user, smtp_password)
|
||||
serveur.send_message(msg)
|
||||
log.info(f"Email envoye a {destinataire}")
|
||||
_sauvegarder_email_historique(destinataire)
|
||||
return True
|
||||
except (smtplib.SMTPException, OSError) as e:
|
||||
log.error(f"Erreur envoi email : {e}")
|
||||
return False
|
||||
|
||||
|
||||
FICHIER_EMAILS = RACINE / "data" / "emails_history.json"
|
||||
|
||||
|
||||
def _sauvegarder_email_historique(email: str):
|
||||
historique = charger_emails_historique()
|
||||
email_lower = email.lower().strip()
|
||||
if email_lower not in historique:
|
||||
historique.append(email_lower)
|
||||
try:
|
||||
with open(FICHIER_EMAILS, "w", encoding="utf-8") as f:
|
||||
json.dump(historique, f, ensure_ascii=False)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def charger_emails_historique() -> list:
|
||||
if not FICHIER_EMAILS.exists():
|
||||
return []
|
||||
try:
|
||||
with open(FICHIER_EMAILS, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except (json.JSONDecodeError, OSError):
|
||||
return []
|
||||
|
||||
|
||||
def effacer_emails_historique():
|
||||
if FICHIER_EMAILS.exists():
|
||||
FICHIER_EMAILS.unlink()
|
||||
|
||||
Reference in New Issue
Block a user