Commit Graph

28 Commits

Author SHA1 Message Date
steve c99eaedafd feat(send): Phase 2 send path — SMTP, MIME, reply threading, outbound policy
Adds the `send` agent command and everything behind it:

- store: Account carries SMTP host/port/security (NULL-safe scan/insert/select);
  admin `account add` gains --smtp-* flags (applied for RW accounts).
- policy: OutboundRule.Check(recipients) → (ok, reason); RO ⇒ ro_mode,
  whitelist-out blocks the whole send if any recipient fails (no partial send).
- mail: Header.References; OutgoingMessage + BuildMIME (plain text + attachments,
  In-Reply-To/References threading, Bcc envelope-only); SendSMTP (tls/starttls,
  SASL PLAIN, envelope send) via emersion/go-smtp.
- cli: SendCmd gates outbound, resolves --reply-to under the inbound filter
  (filtered/absent source ⇒ not_found), reads attachments, audits, emits the
  JSON envelope; repeatable --to/--cc/--bcc/--attach flags wired into the router.

Implemented test-first; full suite passes incl -race. Validated live against
friday.mxlogin.com: real send to me@stevecliff.com, RO + whitelist-out blocks,
and --reply-to threading off a live INBOX message. test-creds.md gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 17:39:07 +01:00
steve 3224a87b6e docs: status report — live validation done, header-only fetch resolved
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 07:52:42 +01:00
steve 5d2461ad94 fix(mail): drain UidFetch channel on early error; clarify ParseHeaderOnly doc
If header/body parsing errored mid-fetch we returned without draining the
message channel, so the UidFetch goroutine could block on a full channel.
Both fetch paths now break, drain remaining messages, then read the done
error. Verified with the race detector.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 07:51:45 +01:00
steve 8379fddbb2 perf(mail): fetch only headers for list/search (no body download)
list and search now fetch BODY.PEEK[HEADER] + BODYSTRUCTURE instead of the
whole RFC822 message, so listing a large mailbox no longer downloads every
message body and attachment. Header parsing reuses the same go-message path
(RFC2047 decoding/formatting preserved); has_attachments is derived from the
BODYSTRUCTURE tree. FetchFull keeps fetching the full message for get.

Validated end-to-end against a live IMAP account: list/search/get output
identical to the prior full-fetch behaviour, has_attachments correct.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 07:47:27 +01:00
steve a1440719ae docs: Phase 1 status report
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 00:19:05 +01:00
steve 6061bd2a78 fix(cli): search limit counts visible results, filter before cap
Pass 0 (unlimited) to m.Search so the mail layer returns all matching
headers; the existing post-filter loop already caps at the caller's
limit, mirroring ListCmd. Add TestSearchLimitCountsVisibleOnly to prove
filtering happens before the cap.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-22 00:17:39 +01:00
steve dd181ef63c fix(cli): non-zero exit when an agent command emits an error envelope
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-22 00:13:29 +01:00
steve e1e5f245e1 feat(cli): command router, real IMAP wiring, flag-based admin
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 00:09:38 +01:00
steve e1d86dc587 fix(cli): reuse folder uidvalidity from setup in AckCmd
Thread uidv through setup's return value (new uint32 before the cleanup
func) so AckCmd no longer makes a redundant SelectFolder round-trip that
silently returned 0 on failure and recorded acks under the wrong
UID-validity epoch. All four callers updated; read-only callers ignore
the value with _.
2026-06-22 00:06:26 +01:00
steve ccf6fa0542 feat(cli): agent read commands (list/get/search/ack) with policy filtering 2026-06-22 00:03:27 +01:00
steve 05abcf3bac feat(cli): JSON output envelope with stable error codes
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 00:00:25 +01:00
steve 47f877ad82 fix(mail): apply search limit and propagate body read error
- Cap search results to limit (keep most-recent UIDs)
- Propagate io.ReadAll errors from body reads in fetchByUIDSet

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 23:58:09 +01:00
steve 83bf3019c5 feat(mail): IMAP client — select, fetch headers/full, search
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 23:55:30 +01:00
steve 7df0c95339 fix(mail): propagate io.ReadAll errors when parsing parts 2026-06-21 23:53:24 +01:00
steve d73aabca96 feat(mail): RFC822 message parsing (headers, body, attachments)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-21 23:51:29 +01:00
steve b9d0b57f84 feat(policy): inbound whitelist + subject-regex filter 2026-06-21 23:49:04 +01:00
steve 4d6ac3e7c6 feat(policy): case-insensitive address and domain matching 2026-06-21 23:47:39 +01:00
steve 5fb022bbaf feat(store): audit log with retention-based purge 2026-06-21 23:45:57 +01:00
steve a4e72b2178 feat(store): seen-set read state with floor baseline and compaction 2026-06-21 23:43:35 +01:00
steve a1e9f601ce feat(store): per-account inbound/outbound whitelist CRUD
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 23:41:10 +01:00
steve 2db459d701 feat(store): accounts CRUD with encrypted password column 2026-06-21 23:38:51 +01:00
steve aaab744b15 fix(store): pin connection pool so foreign_keys pragma sticks
SQLite PRAGMAs are connection-scoped, but database/sql uses a connection
pool. Without pinning to one connection, new pooled connections won't have
foreign_keys enabled, breaking ON DELETE CASCADE enforcement.

Also mark modernc.org/sqlite as a direct dependency in go.mod.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 23:37:11 +01:00
steve 673ed5f350 feat(store): open encrypted SQLite, schema v1, settings 2026-06-21 23:34:31 +01:00
steve 8d04b0fde9 feat(crypto): AES-256-GCM field encryption keyed from EMCLI_KEY
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 23:32:23 +01:00
steve afad3bf3f1 feat: project scaffold, version command, build 2026-06-21 23:30:44 +01:00
steve 04d3b61bb0 Plan: Phase 1 — foundation & read path implementation plan
TDD task-by-task plan for the read-only emcli: crypto, encrypted store,
seen-set read state, policy filtering, IMAP read, and the agent
list/get/search/ack commands with flag-based admin. Phases 2-4 (send,
OAuth2, TUI) to follow as their own plans.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 21:17:29 +01:00
steve e3f8afbc7c Spec: replace read pointer with per-message seen-set model
Reading state is now a per-(account,folder) floor plus an acked set of
UIDs above it, instead of a single monotonic pointer. This makes
acknowledgement per-message and order-independent so concurrent
subagents can process and ack out of order. Internal compaction collapses
contiguous acked runs into the floor to bound storage. Adds stateless
search and ack commands; reads no longer mutate state.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 21:01:34 +01:00
steve 79b62b24c2 Initial commit: PRD and SPEC for emcli
emcli is a Go CLI that mediates an AI agent's email access, enforcing
per-account read/send restrictions so credentials never reach the agent.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 19:36:13 +01:00