28 lines
1 KiB
Python
28 lines
1 KiB
Python
from app.services.mime_parser import parse_mime
|
|
|
|
|
|
def test_parse_mime_extracts_fallback_sender_bodies_and_attachments():
|
|
raw = (
|
|
b"From: sender@example.com\r\n"
|
|
b"To: User <user@getall.help>\r\n"
|
|
b"Subject: Production test\r\n"
|
|
b"Message-ID: <one@example.com>\r\n"
|
|
b"MIME-Version: 1.0\r\n"
|
|
b'Content-Type: multipart/mixed; boundary="b"\r\n\r\n'
|
|
b"--b\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nHello world\r\n"
|
|
b"--b\r\nContent-Type: application/octet-stream\r\n"
|
|
b'Content-Disposition: attachment; filename="sample.bin"\r\n\r\nabc\r\n'
|
|
b"--b--\r\n"
|
|
)
|
|
|
|
parsed = parse_mime(raw)
|
|
|
|
assert parsed["sender"] == {
|
|
"name": "sender",
|
|
"address": "sender@example.com",
|
|
}
|
|
assert parsed["subject"] == "Production test"
|
|
assert parsed["snippet"] == "Hello world"
|
|
assert parsed["body_text"] == "Hello world"
|
|
assert parsed["attachments"][0]["filename"] == "sample.bin"
|
|
assert parsed["attachments"][0]["size"] == 3
|