Add RFC email headers to report messages

This commit is contained in:
2026-05-20 15:26:01 +02:00
parent a19039a4fb
commit 6bdddc3d54
2 changed files with 29 additions and 1 deletions
+15 -1
View File
@@ -1,7 +1,11 @@
from pathlib import Path
from pve_backup_report.config import EmailConfig
from pve_backup_report.email_report import build_report_message, send_report_email
from pve_backup_report.email_report import (
build_report_message,
message_id_domain,
send_report_email,
)
def test_build_report_message_attaches_pdf(tmp_path: Path) -> None:
@@ -20,6 +24,9 @@ def test_build_report_message_attaches_pdf(tmp_path: Path) -> None:
assert message["Subject"] == "Rapport PVE"
assert message["From"] == "report@example.invalid"
assert message["To"] == "admin@example.invalid"
assert message["Date"]
assert message["Message-ID"].endswith("@example.invalid>")
assert message["Auto-Submitted"] == "auto-generated"
attachments = list(message.iter_attachments())
assert len(attachments) == 1
assert attachments[0].get_filename() == "rapport.pdf"
@@ -27,6 +34,13 @@ def test_build_report_message_attaches_pdf(tmp_path: Path) -> None:
assert attachments[0].get_payload(decode=True) == b"%PDF-1.7"
def test_message_id_domain_uses_sender_domain() -> None:
assert message_id_domain("PVE Report <pve@example.invalid>") == "example.invalid"
assert message_id_domain("pve@example.invalid") == "example.invalid"
assert message_id_domain("invalid") is None
assert message_id_domain(None) is None
def test_send_report_email_uses_starttls_and_auth(tmp_path: Path, monkeypatch) -> None:
pdf_path = tmp_path / "rapport.pdf"
pdf_path.write_bytes(b"%PDF-1.7")