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

+32
View File
@@ -0,0 +1,32 @@
#!/bin/bash
set -e
OUTPUT_DIR="output/survey_paper"
mkdir -p "$OUTPUT_DIR"
# Copy template files to output
if [ ! -f "$OUTPUT_DIR/main.tex" ]; then
cp templates/survey/main.tex "$OUTPUT_DIR/"
fi
# Copy sections and bibliography
cp -r templates/survey/sections "$OUTPUT_DIR/" 2>/dev/null || true
cp templates/survey/figures "$OUTPUT_DIR/" 2>/dev/null || true
cd "$OUTPUT_DIR"
echo "First pdflatex run..."
pdflatex -interaction=nonstopmode main.tex || true
echo "Running bibtex..."
if [ -f bibliography.bib ]; then
bibtex main || true
fi
echo "Second pdflatex run..."
pdflatex -interaction=nonstopmode main.tex || true
echo "Final pdflatex run..."
pdflatex -interaction=nonstopmode main.tex || true
echo "Compilation complete. PDF: $OUTPUT_DIR/main.pdf"
Whitespace-only changes.
+61
View File
@@ -0,0 +1,61 @@
% =================================================================
% SURVEY PAPER TEMPLATE
% =================================================================
\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath,amssymb,amsfonts}
% Helvetica for \sffamily so figure labels match the Nature/Science sans-serif
% convention, while body text stays serif (familydefault unchanged).
\usepackage[scaled]{helvet}
% Nature-ish figure palette (used by TikZ/forest diagrams). Wong palette in scripts.
\usepackage{xcolor}
\definecolor{nblue}{HTML}{0072B2}
\definecolor{ngrey}{HTML}{4D4D4D}
\definecolor{nfill}{HTML}{EAF2FB}
\usepackage[a4paper, margin=1in]{geometry}
\usepackage[numbers,sort&compress]{natbib}
\usepackage{hyperref}
\usepackage{booktabs}
\usepackage{microtype}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{enumitem}
\usepackage{array}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{subcaption}
% Taxonomy/diagram figures: TikZ for drawing, forest for auto-spaced trees
% (taxonomies MUST use forest, not hand-tuned sibling distances — see
% references/02-survey-figures.md). graphicx
% (above) provides \resizebox for clamping any figure to \linewidth.
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric, arrows.meta, fit, backgrounds, calc, trees}
\usepackage{forest}
% Custom commands
\newcommand{\todo}[1]{\textcolor{red}{[TODO: #1]}}
\title{\textbf{{{TITLE}}}}
% Author defaults to "AI4S Agent". The enrichment step
% (see SKILL.md Step 3) is responsible for
% adding a \thanks footnote that recommends human review. Surveys do NOT
% include a simulated clause (no numerical experiments).
\author{AI4S Agent}
\date{\today}
\begin{document}
\maketitle
\input{sections/abstract}
\input{sections/introduction}
\input{sections/related_work}
\input{sections/background}
\input{sections/methods}
\input{sections/discussion}
\input{sections/conclusion}
\bibliographystyle{plainnat}
\bibliography{bibliography}
\end{document}
Whitespace-only changes.