c-stone-invoice-check/backend/tests/test_classify.py
Markus Kruse db8dc1dae3 feat(picker): Grabber (Direktlink-Download), Outbound-Queue, Accountable-Versand mit Freigabe
- Klassifikator: Direktlink nur Allowlist/https-PDF, Login-/Konsolen-Links -> portal
- grabber.py: INBOX/Archive/Trash readonly, Dedupe Message-ID + SHA-256
- Stichtag GRAB_CUTOFF: Rückblick = pending_review, neu = queued
- mailer.py: SMTP an ACCOUNTABLE_INBOX (ohne Adresse kein Versand)
- /outbound: Liste/xlsx, PDF-Vorschau, approve, run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 21:55:17 +01:00

25 lines
1.4 KiB
Python

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\n<a href="https://x.example/r.pdf?a=1&amp;b=2">Rechnung</a>'
assert classify_mail(_m(h)) == ("link", "https://x.example/r.pdf?a=1&b=2")