Files
Z User e45b68bb8b 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
2026-10-27 22:50:50 +00:00

49 lines
1.2 KiB
Python
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""提交测验答案并评分。
用法:python3 submit_answers.py <user_id> <document_id> <session_id> <answers_json>
参数:
user_id: 用户标识
document_id: 文档标识
session_id: 测验会话 ID
answers_json: JSON 格式的答案字典,如 '{"q_001":"A","q_002":"True"}'
输出:评分结果 JSON(score, total, accuracy, results)。
"""
from pathlib import Path
import json
import sys
sys.path.append(str(Path(__file__).resolve().parents[1] / "src"))
from quiz_mastery import QuizMasteryService
def main() -> None:
if len(sys.argv) < 5:
print("Usage: submit_answers.py <user_id> <document_id> <session_id> <answers_json>")
sys.exit(1)
user_id = sys.argv[1]
document_id = sys.argv[2]
session_id = sys.argv[3]
answers = json.loads(sys.argv[4])
service = QuizMasteryService(
base_dir=Path(__file__).resolve().parents[1] / "data"
)
result = service.submit_quiz_answers(
user_id=user_id,
document_id=document_id,
session_id=session_id,
answers=answers,
)
print(json.dumps(result, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()