Compare commits

...

2 Commits

Author SHA1 Message Date
59b478d854 Amélioration de l'entête 2025-02-13 17:05:42 +01:00
220b102830 Nettoyage du HTML 2025-02-13 17:01:17 +01:00

View File

@ -22,6 +22,11 @@ def extract_and_convert_email(message, output_file_base, i):
try:
payload = part.get_payload(decode=True).decode(charset, errors='replace')
soup = BeautifulSoup(payload, 'html.parser')
# Nettoyage de l'HTML
attr_whitelist = ("style")
for tag in soup.findAll(True):
for attr in [attr for attr in tag.attrs if attr not in attr_whitelist]:
del tag[attr]
html_content = str(soup)
# Extraction de la date et formatage ISO
@ -38,11 +43,11 @@ def extract_and_convert_email(message, output_file_base, i):
logging.warning(f"Format de date invalide: {date_header}")
output_file = os.path.join(output_file_base, f"email_{i}") # Nom par défaut si date invalide
date_simple = "<i>date inconnue</i>"
html_header = "<p><ul>"
html_header = "<div style=\"border: thick double black;\"><ul>"
html_header += f"<li>De : {from_header}</li>"
html_header += f"<li>&#192; : {to_header}</li>"
html_header += f"<li>Date : {date_simple}</li>"
html_header += "</ul><br /></p>"
html_header += "</ul><br /></div>"
# Conversion en PDF
try:
html_content = html_header + html_content