diff --git a/tools/email_process.py b/tools/email_process.py index 03d4539..5d5b0ee 100755 --- a/tools/email_process.py +++ b/tools/email_process.py @@ -37,6 +37,8 @@ KB_PATH = PROJECT_ROOT / "memory" / "kb" / "emails" def slugify(text: str, max_len: int = 50) -> str: """Convert text to URL-friendly slug""" + # Strip spam prefix added by mail server + text = re.sub(r'^\*+SPAM\*+\s*', '', text, flags=re.IGNORECASE) text = text.lower() text = re.sub(r'[^\w\s-]', '', text) text = re.sub(r'[\s_]+', '-', text) @@ -164,13 +166,17 @@ def list_emails(show_all=False): subject = decode_mime_header(msg['Subject']) date = msg['Date'] + # Accept forwarded emails (Fwd:) regardless of original sender + # echo@romfast.ro is private — only Marius forwards to it + subject_lower = subject.lower() + is_forward = 'fwd:' in subject_lower emails.append({ 'id': eid.decode(), 'from': from_addr, 'sender_email': sender_email, 'subject': subject, 'date': date, - 'whitelisted': sender_email in WHITELIST + 'whitelisted': sender_email in WHITELIST or is_forward }) mail.logout() @@ -192,8 +198,10 @@ def save_email_as_note(eid: str) -> dict: body = get_email_body(msg) attachments = get_email_attachments(msg) - # Check whitelist - if sender_email not in WHITELIST: + # Check whitelist — accept forwarded emails regardless of original sender + # echo@romfast.ro is private — only Marius forwards to it + is_forward = 'fwd:' in subject.lower() + if sender_email not in WHITELIST and not is_forward: mail.logout() return {'ok': False, 'error': f'Sender {sender_email} not in whitelist'}