feat(email): show attachments in digest and forward commands

Add get_email_attachments() helper that extracts filenames from MIME
parts. Email notes now include an Atașamente section; forwarded emails
show attachment names in the WhatsApp header.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-22 07:41:21 +00:00
parent eb693a2e71
commit 56f6c0df01
2 changed files with 32 additions and 6 deletions

View File

@@ -80,6 +80,19 @@ def get_email_body(msg):
body = payload.decode(charset, errors='replace')
return body.strip()
def get_email_attachments(msg) -> list:
"""Extract list of attachment filenames from email MIME parts."""
attachments = []
if not msg.is_multipart():
return attachments
for part in msg.walk():
filename = part.get_filename()
if filename:
attachments.append(decode_mime_header(filename))
elif part.get('Content-Disposition', '').lower().startswith('attachment'):
attachments.append(f"[{part.get_content_type()}]")
return attachments
def extract_sender_email(from_header: str) -> str:
"""Extract just the email address from From header"""
match = re.search(r'<([^>]+)>', from_header)
@@ -137,7 +150,8 @@ def save_email_as_note(eid: str) -> dict:
subject = decode_mime_header(msg['Subject'])
date_str = msg['Date']
body = get_email_body(msg)
attachments = get_email_attachments(msg)
# Check whitelist
if sender_email not in WHITELIST:
mail.logout()
@@ -162,6 +176,12 @@ def save_email_as_note(eid: str) -> dict:
filename = f"{date_prefix}_{slug}.md"
filepath = KB_PATH / filename
# Build attachments section
attachments_section = ""
if attachments:
att_list = "\n".join(f"- {a}" for a in attachments)
attachments_section = f"\n## Atașamente\n{att_list}\n"
# Create markdown note
content = f"""# {subject}
@@ -172,7 +192,7 @@ def save_email_as_note(eid: str) -> dict:
---
{body}
{attachments_section}
---
## TL;DR