Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(email): exclude attached messages from body extraction
fhgffyaef8127aff1b
diff --git a/nanobot/channels/email/runtime.py b/nanobot/channels/email/runtime.pyindex 92f9beaaf..e4b3e81ff 100644--- a/nanobot/channels/email/runtime.py+++ b/nanobot/channels/email/runtime.py@@ -845,9 +845,14 @@ class EmailChannel(BaseChannel):if msg.is_multipart():plain_parts: list[str] = []html_parts: list[str] = []- for part in msg.walk():+ parts = [msg]+ while parts:+ part = parts.pop()if part.get_content_disposition() == "attachment":continue+ if part.is_multipart():+ parts.extend(reversed(part.get_payload()))+ continuecontent_type = part.get_content_type()try:payload = part.get_content()diff --git a/nanobot/channels/email/tests/test_attached_message_body.py b/nanobot/channels/email/tests/test_attached_message_body.pynew file mode 100644index 000000000..939f7721a--- /dev/null+++ b/nanobot/channels/email/tests/test_attached_message_body.py@@ -0,0 +1,26 @@+from email import policy+from email.message import EmailMessage+from email.parser import BytesParser++from nanobot.channels.email.runtime import EmailChannel+++def test_attached_email_is_not_included_in_message_body():+ message = EmailMessage()+ message.set_content("Please review the attached email.")+ attachment = EmailMessage()+ attachment["Subject"] = "Forwarded conversation"+ attachment.set_content("This belongs to the attached conversation.")+ message.add_attachment(attachment, filename="forwarded.eml")+ parsed = BytesParser(policy=policy.default).parsebytes(message.as_bytes())++ assert EmailChannel._extract_text_body(parsed) == "Please review the attached email."+++def test_multipart_alternative_still_prefers_plain_text():+ message = EmailMessage()+ message.set_content("Plain body.")+ message.add_alternative("<p>HTML body.</p>", subtype="html")+ parsed = BytesParser(policy=policy.default).parsebytes(message.as_bytes())++ assert EmailChannel._extract_text_body(parsed) == "Plain body."