fix: email pre-retrieval ignores contacts (reads non-existent email/phone keys) (#1241)
* fix: match known email senders against the contact 'emails' list * fix: build contact-match snippets from emails/phones lists
This commit is contained in:
@@ -1154,7 +1154,10 @@ def _pre_retrieve_context(body: str, sender: str) -> tuple:
|
||||
try:
|
||||
from routes.contacts_routes import _fetch_contacts
|
||||
for c in _fetch_contacts() or []:
|
||||
if (c.get("email") or "").lower() == sender_addr:
|
||||
# Contacts are normalized to plural `emails` lists (see
|
||||
# contacts_routes._normalize_contact); the old `c.get("email")`
|
||||
# singular key never exists, so known senders were never matched.
|
||||
if sender_addr in [(e or "").lower() for e in (c.get("emails") or [])]:
|
||||
is_known = True
|
||||
break
|
||||
except Exception:
|
||||
@@ -1248,13 +1251,13 @@ def _pre_retrieve_context(body: str, sender: str) -> tuple:
|
||||
t_lower = term.lower()
|
||||
matches = [c for c in all_contacts
|
||||
if t_lower in (c.get("name") or "").lower()
|
||||
or t_lower in (c.get("email") or "").lower()]
|
||||
or any(t_lower in (e or "").lower() for e in (c.get("emails") or []))]
|
||||
for c in matches[:2]:
|
||||
parts = [f"Name: {c.get('name','')}"]
|
||||
if c.get("email"):
|
||||
parts.append(f"Email: {c['email']}")
|
||||
if c.get("phone"):
|
||||
parts.append(f"Phone: {c['phone']}")
|
||||
if c.get("emails"):
|
||||
parts.append(f"Email: {', '.join(c['emails'])}")
|
||||
if c.get("phones"):
|
||||
parts.append(f"Phone: {', '.join(c['phones'])}")
|
||||
context_snippets.append(f"[Contact match for \"{term}\"] " + ", ".join(parts))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user