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): preserve attachments with colliding filenames
fhgffy38c92558ca6e
diff --git a/nanobot/channels/email/runtime.py b/nanobot/channels/email/runtime.pyindex e4b3e81ff..d903c4d9d 100644--- a/nanobot/channels/email/runtime.py+++ b/nanobot/channels/email/runtime.py@@ -1222,7 +1222,12 @@ class EmailChannel(BaseChannel):raw_name = part.get_filename() or "attachment"sanitized = safe_filename(raw_name) or "attachment"- dest = media_dir / f"{uid}_{sanitized}"+ filename = Path(f"{uid}_{sanitized}")+ dest = media_dir / filename+ index = 1+ while dest in saved:+ dest = media_dir / f"{filename.stem}_{index}{filename.suffix}"+ index += 1try:dest.write_bytes(payload)diff --git a/nanobot/channels/email/tests/test_attachment_filenames.py b/nanobot/channels/email/tests/test_attachment_filenames.pynew file mode 100644index 000000000..81a80ea26--- /dev/null+++ b/nanobot/channels/email/tests/test_attachment_filenames.py@@ -0,0 +1,31 @@+"""Inbound attachment names must not cause another attachment to be overwritten."""++from email.message import EmailMessage++import pytest++from nanobot.channels.email.runtime import EmailChannel+++ "filenames",+ [+ ("report.txt", "report.txt"),+ ("report:2026.txt", "report?2026.txt"),+ ("report.txt", "report.txt", "report_1.txt"),+ ],+)+def test_extract_attachments_preserves_colliding_filenames(tmp_path, monkeypatch, filenames):+ monkeypatch.setattr("nanobot.channels.email.runtime.get_media_dir", lambda _channel: tmp_path)+ message = EmailMessage()+ message.set_content("Both reports are attached.")+ contents = [f"report {index}".encode() for index in range(len(filenames))]+ for filename, content in zip(filenames, contents):+ message.add_attachment(content, maintype="text", subtype="plain", filename=filename)++ paths = EmailChannel._extract_attachments(+ message, "500", allowed_types=["text/plain"], max_size=100, max_count=len(filenames),+ )++ assert len(paths) == len(set(paths)) == len(filenames)+ assert [path.read_bytes() for path in paths] == contents