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:
1 parent
7acc0c5451
commit
e45b68bb8b
1089 files changed
+260614
No files matched your search
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Unpack and format XML contents of Office files (.docx, .pptx, .xlsx)"""
|
||||
|
||||
import argparse
|
||||
import random
|
||||
import zipfile
|
||||
import defusedxml.minidom
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Unpack an Office file into a directory")
|
||||
parser.add_argument("office_file", help="Office file (.docx/.pptx/.xlsx)")
|
||||
parser.add_argument("output_dir", help="Output directory")
|
||||
args = parser.parse_args()
|
||||
unpack_document(args.office_file, args.output_dir)
|
||||
|
||||
|
||||
def unpack_document(input_file, output_dir):
|
||||
"""Unpack an Office file into a directory and pretty-print all XML files."""
|
||||
output_path = Path(output_dir)
|
||||
output_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with zipfile.ZipFile(input_file) as zf:
|
||||
zf.extractall(output_path)
|
||||
|
||||
for pattern in ["*.xml", "*.rels"]:
|
||||
for xml_file in output_path.rglob(pattern):
|
||||
pretty_print_xml(xml_file)
|
||||
|
||||
# For .docx files, suggest an RSID for tracked changes
|
||||
if str(input_file).endswith(".docx"):
|
||||
suggested_rsid = "".join(random.choices("0123456789ABCDEF", k=8))
|
||||
print(f"Suggested RSID for edit session: {suggested_rsid}")
|
||||
|
||||
|
||||
def pretty_print_xml(xml_file):
|
||||
"""Pretty-print a single XML file in place."""
|
||||
content = xml_file.read_text(encoding="utf-8")
|
||||
dom = defusedxml.minidom.parseString(content)
|
||||
xml_file.write_bytes(dom.toprettyxml(indent=" ", encoding="ascii"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user