From c401204fa2591dcb26b12acacd53369456aba139 Mon Sep 17 00:00:00 2001 From: Marius Mutu Date: Fri, 29 May 2026 13:28:47 +0000 Subject: [PATCH] fix(email): accept forwarded emails regardless of original sender MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gmail preserves the original sender when forwarding — whitelist check was blocking all Fwd: emails not from mmarius28@gmail.com. echo@romfast.ro is private, so any Fwd: arriving there is from Marius. Also strip ***SPAM*** prefix from slugs for cleaner filenames. Co-Authored-By: Claude Sonnet 4.6 --- tools/email_process.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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'}