From 9b51272413df4849d38ce8d76ece35657befecb0aa489064f6b455e3316950ca Mon Sep 17 00:00:00 2001 From: tlg Date: Thu, 9 Jul 2026 16:24:34 +0200 Subject: [PATCH] test(projekt-matching): gate 1 e2e passed (consider path via e-mail) --- projekt-matching/tests/e2e/send_test_mail.py | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 projekt-matching/tests/e2e/send_test_mail.py diff --git a/projekt-matching/tests/e2e/send_test_mail.py b/projekt-matching/tests/e2e/send_test_mail.py new file mode 100755 index 0000000..2736d07 --- /dev/null +++ b/projekt-matching/tests/e2e/send_test_mail.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +"""Re-send an original example mail (found by subject) as a fresh test mail +from chancen@ to chancen@. Fallback: synthetic single-project mail.""" +import os +import smtplib +import ssl +import sys +import time +from email.message import EmailMessage +from email.policy import default as default_policy + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..")) +from projektmatch import mailer, mailparse # noqa: E402 + +USER = "chancen@destengs.com" +PW = os.environ["PM_IMAP_PASSWORD"] +SUBJECT = sys.argv[1] # e.g. "Example 1 for Langflow process" +FALLBACK_URL = sys.argv[2] if len(sys.argv) > 2 else "" + +box = mailer.MailBox(USER, PW) +html = "" +for folder in ("INBOX", box.trash_folder()): + box.conn.select(folder) + typ, data = box.conn.uid("SEARCH", None, + f'SUBJECT "{SUBJECT}"') + uids = data[0].split() if data and data[0] else [] + if uids: + msg = box.fetch(uids[-1].decode()) + html, _ = mailparse.bodies(msg) + break +box.close() + +out = EmailMessage(policy=default_policy) +out["From"], out["To"] = USER, USER +out["Subject"] = f"Test {SUBJECT} {int(time.time())}" +if html: + out.set_content("siehe HTML") + out.add_alternative(html, subtype="html") + print(f"re-sending original '{SUBJECT}' body") +else: + if not FALLBACK_URL: + sys.exit(f"original mail '{SUBJECT}' not found and no fallback URL") + out.set_content(f"Neues Projekt:\n\nTestprojekt\n{FALLBACK_URL}\n") + print("original not found -> synthetic fallback mail") +with smtplib.SMTP(mailer.SMTP_HOST, mailer.SMTP_PORT, timeout=30) as server: + server.starttls(context=ssl.create_default_context()) + server.login(USER, PW) + server.send_message(out) +print(f"sent: {out['Subject']}")