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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user