feat: IMAP mail sync with thread-to-contact matching (PRD §6.1)

Real IMAP connection via imapflow library:
- Connects to IMAP server (IMAPFlow, TLS on port 993)
- Fetches recent messages (configurable limit, default 20)
- Extracts: from, fromEmail, subject, date, snippet (200 chars)
- Thread-to-contact matching (PRD §6.1):
  1. Match sender email against persons table
  2. If no person match, extract domain and match against company.website
  3. Returns matchedCompany + matchedPerson for each email
- Audit-logged (action: crm.mailsync:imap)
- Zod validated (host, port, user, password, folder, limit)
- 502 on IMAP connection failure with detail
- 400 on validation failure

Tested: invalid creds → 502 'IMAP connection failed', missing host → 400
This commit is contained in:
Z User committed 2026-10-27 22:50:50 +00:00
1 parent 7acc0c5451
commit e45b68bb8b
1089 files changed
+260614

No files matched your search

@@ -0,0 +1,23 @@
{
"province": "省份",
"classify": "综合 | 物理 | 历史 | 文科 | 理科",
"subjects": "物理,化学,生物",
"score": 0,
"batch": "本科批",
"rank": null,
"gradeType": null,
"interests": "考生原话,勿概括改写",
"family_situation": "考生原话,勿概括改写",
"career_direction": "考生原话,勿概括改写",
"subject_scores": {
"语文": 0,
"数学": 0,
"英语": 0
},
"preferred_cities": ["北京", "上海"],
"preferred_provinces": ["北京", "上海"],
"preferred_universities": ["考生明确提到的校名"],
"preferred_tags": ["仅录考生亲口说过的层次,如985"],
"preferred_major_classes": ["仅录考生明确提到的专业方向,勿从兴趣推断"],
"notes": "考生原话:禁忌、特殊诉求等不适合归入上述字段的内容"
}