TaxHacker icon indicating copy to clipboard operation
TaxHacker copied to clipboard

Working IMAP email ingest (builds on the scaffold)

Open Freika opened this issue 5 months ago • 0 comments

Builds on the email scaffold in this branch and turns it into a working, tested IMAP fetcher. Ingest-only: attachments land in the existing unsorted bucket and flow through the normal Analyze → transaction review.

What it adds (vs. the scaffold)

  • Real IMAP: imap-simple + mailparser (replaces the mock client).
  • Reuses the upload pipeline: a shared ingestUnsortedFile helper writes attachments exactly like a manual upload (no hand-rolled file create).
  • Credentials encrypted at rest: AES-256-GCM, key derived from BETTER_AUTH_SECRET; decrypted only at sync/test time.
  • Non-destructive dedup: per-server highest-UID watermark; mail is fetched read-only and never marked as read.
  • Configurable first grab: a "fetch emails since" date (blank = entire mailbox).
  • Per-server sync interval enforced on the cron run; manual "Sync Now" bypasses it.
  • Tests: a vitest suite (19 tests) for encryption, filters, ingest orchestration.

Notes

  • Adds @langchain/core as an explicit dependency (it was a missing peer that broke a clean npm install).
  • Rotating BETTER_AUTH_SECRET invalidates stored mailbox passwords (re-enter them) — documented in the app README.

Test plan

  • [ ] Configure a mailbox, drop a PDF in the inbox, run npm run email:sync, confirm it appears in /unsorted and analyzes.
  • [ ] Re-run sync → 0 new (UID watermark); read state untouched.

Freika avatar Jun 12 '26 18:06 Freika