Skip to content

Agent Zero AI framework

fix(email): use RFC to save inbound attachments into execution runtime

linuztx42487055f390
diff --git a/plugins/_email_integration/helpers/attachment_writer.py b/plugins/_email_integration/helpers/attachment_writer.py
new file mode 100644
index 000000000..b2625bbd4
--- /dev/null
+++ b/plugins/_email_integration/helpers/attachment_writer.py
@@ -0,0 +1,36 @@
+"""
+Write attachment files into execution runtime.
+
+No agent/tool dependencies.
+"""
+
+import base64
+import os
+from typing import TypedDict
+
+
+# ------------------------------------------------------------------
+# Data models
+# ------------------------------------------------------------------
+
+class WriteResult(TypedDict):
+ path: str
+ error: str
+
+
+# ------------------------------------------------------------------
+# File writer
+# ------------------------------------------------------------------
+
+def write_attachment(rel_path: str, content_b64: str) -> WriteResult:
+ try:
+ from helpers import files
+ abs_path = files.get_abs_path(rel_path)
+ files.make_dirs(abs_path)
+
+ content = base64.b64decode(content_b64)
+ files.write_file_bin(abs_path, content)
+
+ return WriteResult(path=abs_path, error="")
+ except Exception as e:
+ return WriteResult(path="", error=str(e))
\ No newline at end of file
diff --git a/plugins/_email_integration/helpers/imap_client.py b/plugins/_email_integration/helpers/imap_client.py
index 58107e22d..2fddb0fd8 100644
--- a/plugins/_email_integration/helpers/imap_client.py
+++ b/plugins/_email_integration/helpers/imap_client.py
@@ -412,8 +412,20 @@ async def _save_attachment(filename: str, content: bytes, download_folder: str)
name, ext = os.path.splitext(filename)
unique = f"{name}_{uuid.uuid4().hex[:8]}{ext}"
rel_path = os.path.join(download_folder, unique)
- files.write_file_bin(rel_path, content)
- return files.get_abs_path(rel_path)
+ from helpers import runtime
+ from plugins._email_integration.helpers.attachment_writer import write_attachment
+
+ import base64
+ content_b64 = base64.b64encode(content).decode()
+
+ result = await runtime.call_development_function(
+ write_attachment, rel_path, content_b64
+ )
+ if result.get("error"):
+ from helpers.print_style import PrintStyle
+ PrintStyle.error(f"Failed to save attachment {filename}: {result['error']}")
+
+ return result.get("path", files.get_abs_path(rel_path))
def _decode_header(header: str) -> str: