"""Email channel parsing and reply construction.""" from __future__ import annotations from forge.channels import email as email_ch # --- email parsing --- def test_email_parse_provider_dict(): p = email_ch.parse_inbound({"from": "Jane ", "subject": "Help", "text": " my order is late "}) assert p["from_addr"] == "jane@acme.com" and p["from_name"] == "Jane" and p["text"] == "my order is late" def test_email_parse_raw_mime(): raw = b"From: Bob \r\nSubject: Hi\r\nMessage-ID: \r\nContent-Type: text/plain\r\n\r\nHello body\r\n" p = email_ch.parse_inbound(raw) assert p["from_addr"] == "bob@x.com" and "Hello body" in p["text"] and p["message_id"] == "" def test_email_reply_threads_subject(): msg = email_ch.build_reply(to_addr="a@b.com", subject="Order", body="done", from_addr="bot@x.com", in_reply_to="") assert msg["Subject"] == "Re: Order" and msg["In-Reply-To"] == "" and msg["To"] == "a@b.com"