fix(email): accept forwarded emails regardless of original sender
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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'}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user