Coverage for app/backend/src/tests/test_smtp.py: 100%
8 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-05-29 04:01 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-05-29 04:01 +0000
1from couchers.email.smtp import email_proto_to_message
2from couchers.proto.internal.jobs_pb2 import EmailAttachmentV2, SendEmailPayload
5def test_verbatim_attachment_headers():
6 """
7 Test that specified Content-Type/Content-Disposition are preserved verbatim (with original quoting).
8 This ensures we can create attachments compatible with older email clients.
9 """
11 send_email_payload = SendEmailPayload(
12 sender_name="alice",
13 sender_email="alice@couchers.org",
14 recipient="bob@couchers.org",
15 subject="greeting",
16 plain="hello",
17 attachments=[
18 EmailAttachmentV2(
19 data=bytes([0, 255]), # Force base64 encoding
20 content_type='maintype/subtype; quoted-header="value"; unquoted-header=value',
21 content_disposition="attachment",
22 )
23 ],
24 )
26 email_message, _ = email_proto_to_message(send_email_payload, couchers_id="42")
27 smtp_str = email_message.as_string()
29 expected_snippet = """
30Content-Type: maintype/subtype; quoted-header="value"; unquoted-header=value
31Content-Transfer-Encoding: base64
32Content-Disposition: attachment
33MIME-Version: 1.0
34 """.strip()
36 assert expected_snippet in smtp_str