import email from backend.routers.emails import classify_mail def _m(raw): return email.message_from_string(raw) def test_classify(): pdf = "Content-Type: multipart/mixed; boundary=b\n\n--b\nContent-Type: text/plain\n\nhi\n--b\nContent-Type: application/pdf\nContent-Disposition: attachment; filename=r.pdf\n\nx\n--b--\n" assert classify_mail(_m(pdf)) == ("attachment", None) link = "Content-Type: text/plain\n\nIhre Rechnung: https://pay.stripe.com/invoice/abc/pdf" assert classify_mail(_m(link))[0] == "link" portal = "Content-Type: text/plain\n\nIhre Rechnung ist verfügbar. Bitte in Ihrem Konto herunterladen." assert classify_mail(_m(portal)) == ("portal", None) assert classify_mail(_m("Content-Type: text/plain\n\nHallo"))[0] == "ignore" # Login-/Konsolen-Links sind kein Direktdownload -> portal aws = "Content-Type: text/plain\n\nYour bill: https://console.aws.amazon.com/billing/home#/bills" assert classify_mail(_m(aws)) == ("portal", None) assert classify_mail(_m("Content-Type: text/plain\n\nIhr Zahlungsbeleg liegt bereit."))[0] == "portal" # http (kein TLS) wird nie direkt geladen assert classify_mail(_m("Content-Type: text/plain\n\nRechnung http://x.example/r.pdf"))[0] == "portal" # HTML-Entities im Link werden aufgelöst h = 'Content-Type: text/html\n\nRechnung' assert classify_mail(_m(h)) == ("link", "https://x.example/r.pdf?a=1&b=2")