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:
@@ -17,7 +17,8 @@ sys.path.insert(0, str(PROJECT_ROOT))
|
||||
|
||||
from tools.email_process import (
|
||||
IMAP_SERVER, IMAP_PORT, IMAP_USER, IMAP_PASS,
|
||||
WHITELIST, decode_mime_header, extract_sender_email, get_email_body
|
||||
WHITELIST, decode_mime_header, extract_sender_email, get_email_body,
|
||||
get_email_attachments
|
||||
)
|
||||
from src.config import Config
|
||||
import imaplib
|
||||
@@ -46,7 +47,7 @@ def extract_original_sender(body: str, from_full: str) -> tuple[str, str]:
|
||||
return from_full, ""
|
||||
|
||||
|
||||
def format_for_whatsapp(subject: str, from_full: str, date: str, body: str) -> str:
|
||||
def format_for_whatsapp(subject: str, from_full: str, date: str, body: str, attachments: list = None) -> str:
|
||||
"""Curăță corpul emailului și îl formatează pentru WhatsApp."""
|
||||
# Extrage expeditorul original dacă e forward
|
||||
original_from, original_date = extract_original_sender(body, from_full)
|
||||
@@ -70,7 +71,11 @@ def format_for_whatsapp(subject: str, from_full: str, date: str, body: str) -> s
|
||||
body = '\n'.join(line.rstrip() for line in body.splitlines())
|
||||
body = body.strip()
|
||||
|
||||
header = f"*{subject}*\nDe la: {display_from}\nPrimit: {display_date}\n---\n"
|
||||
att_line = ""
|
||||
if attachments:
|
||||
att_line = "\nAtașamente: " + ", ".join(attachments) + "\n"
|
||||
|
||||
header = f"*{subject}*\nDe la: {display_from}\nPrimit: {display_date}{att_line}\n---\n"
|
||||
full = header + body
|
||||
|
||||
if len(full) <= MAX_WA_LENGTH:
|
||||
@@ -138,6 +143,7 @@ def fetch_unread_emails():
|
||||
'from_full': from_addr,
|
||||
'date': msg['Date'],
|
||||
'body': get_email_body(msg),
|
||||
'attachments': get_email_attachments(msg),
|
||||
})
|
||||
|
||||
mail.logout()
|
||||
@@ -159,7 +165,7 @@ def run_forward():
|
||||
for em in emails:
|
||||
subject = em['subject']
|
||||
print(f"Trimit: {subject}")
|
||||
parts = format_for_whatsapp(subject, em['from_full'], em['date'], em['body'])
|
||||
parts = format_for_whatsapp(subject, em['from_full'], em['date'], em['body'], em.get('attachments', []))
|
||||
|
||||
if DRY_RUN:
|
||||
for i, part in enumerate(parts):
|
||||
|
||||
Reference in New Issue
Block a user