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:
|
try:
|
||||||
from routes.contacts_routes import _fetch_contacts
|
from routes.contacts_routes import _fetch_contacts
|
||||||
for c in _fetch_contacts() or []:
|
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
|
is_known = True
|
||||||
break
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -1248,13 +1251,13 @@ def _pre_retrieve_context(body: str, sender: str) -> tuple:
|
|||||||
t_lower = term.lower()
|
t_lower = term.lower()
|
||||||
matches = [c for c in all_contacts
|
matches = [c for c in all_contacts
|
||||||
if t_lower in (c.get("name") or "").lower()
|
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]:
|
for c in matches[:2]:
|
||||||
parts = [f"Name: {c.get('name','')}"]
|
parts = [f"Name: {c.get('name','')}"]
|
||||||
if c.get("email"):
|
if c.get("emails"):
|
||||||
parts.append(f"Email: {c['email']}")
|
parts.append(f"Email: {', '.join(c['emails'])}")
|
||||||
if c.get("phone"):
|
if c.get("phones"):
|
||||||
parts.append(f"Phone: {c['phone']}")
|
parts.append(f"Phone: {', '.join(c['phones'])}")
|
||||||
context_snippets.append(f"[Contact match for \"{term}\"] " + ", ".join(parts))
|
context_snippets.append(f"[Contact match for \"{term}\"] " + ", ".join(parts))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user