Adds a real :143 IMAP listener to the Go protocols service: a mailbox
owner authenticates over IMAP (Argon2id against mailboxes.password_hash,
enumeration-resistant per PLAN.md section 14.6), lists folders, selects
INBOX, fetches messages F1's SMTP path already persisted - including real
ENVELOPE/BODY[] built from the actual stored MIME bytes via go-imap/v2's
own ExtractEnvelope/ExtractBodySection helpers, not reconstructed from
denormalized columns - and sets/reads flags via STORE.
- ImapSessionUseCase orchestrates auth, folder listing/selection, message
querying, and flag mutation against new Postgres repositories (auth,
folders, message query, flags) and a local-disk blob reader.
- A github.com/emersion/go-imap/v2 (pinned v2.0.0-beta.8) Backend/Session
implements 7 real methods (Login, List, Select, Unselect, Status, Fetch,
Store) plus a correct no-op Poll; the other 10 of the interface's 18
methods (Create/Delete/Rename/Subscribe/Unsubscribe/Append/Idle/Expunge/
Search/Copy) are explicit stubs returning a clear "not yet implemented"
IMAP error - SEARCH/EXPUNGE/COPY/MOVE, IDLE/CONDSTORE, mailbox
management, and APPEND are separate follow-up sub-projects per the
design doc's agreed ordering with the user.
Verified end-to-end with a real go-imap/v2 imapclient (embedded Postgres,
no Docker needed) driving Login -> Select -> Fetch -> Store -> List
against a message seeded through F1's real SMTP use case, proving true
SMTP-write/IMAP-read interop, not just isolated unit tests.
Built via 8 sequential tasks under subagent-driven development, each
independently reviewed, plus a final whole-branch review. Two real bugs
were found and fixed before merge, both exactly the kind unit tests with
fakes cannot catch:
- Store's UID-set resolution silently no-op'd on dynamic ranges like
"UID STORE 1:*" (the common "mark all as read" operation) after an
earlier draft bypassed the folder's real message list; restored to
resolve against real messages via the same pattern Fetch already used
correctly, with tests proving both dynamic ranges and non-UID STORE.
- go-imap/v2's server calls Session.Poll() implicitly before the status
response of nearly every authenticated command (FETCH/STORE/SEARCH/
APPEND/COPY), not just IDLE as assumed - a hard-stubbed Poll broke every
real command through this path; fixed to a correct no-op.
- List had zero test coverage despite being committed scope; added unit
tests for wildcard/delimiter matching plus a real E2E LIST assertion.
Known follow-up, not blocking: a pre-existing test-fixture hygiene gap
(hardcoded content_sha256 blob hashes with no cleanup, shared across
several Postgres integration test files including one new to this
branch) causes local-dev test collisions on repeated runs against a
persistent database - invisible to CI (fresh Postgres per run) but worth
a cleanup pass.
Per feature/3-f0-f1-validation's own gap analysis (commit 097fa37):
- InboundMessageRepository.Persist now updates folders.unread_count,
folders.total_count, and mailboxes.used_bytes in the same transaction
as the message insert (PLAN.md section 6.1 "++counters" was a no-op
before this).
- MailboxRecord carries QuotaBytes/UsedBytes; ResolveRecipient rejects
RCPT with 452 4.2.2 when a target mailbox has already reached its
quota (used_bytes >= quota_bytes), before DATA - never silently
accepting mail into a full mailbox.
- MailboxRepository.ResolveDeliveryTargets tries a direct mailbox match
first, then falls back to the aliases table (exact source_address
match takes precedence over a domain catch-all). One RCPT TO can now
fan out to multiple mailboxes; alias destinations that don't resolve
to an internal active mailbox are silently skipped, since outbound/
external forwarding doesn't exist yet. postmaster@/abuse@/dmarc@-style
aliases now actually deliver.
The E2E test's counters_updated subtest flips from a documented KNOWN
GAP (t.Skipf) to a hard assertion now that it passes, and gains two new
subtests (quota_rejected_when_mailbox_full, alias_resolves_to_destination_mailbox)
covering the other two fixes end-to-end. New unit and Postgres
integration test coverage added for all three fixes at every layer.
Verified: full suite green on Windows (unit + E2E via embedded
Postgres, no Docker needed) and via WSL Docker against the real
docker-compose Postgres (all infrastructure/postgres and diskstorage
integration tests, not just E2E). lang-lint clean.
Boots a real Postgres (no Docker), applies the real migration and seed,
starts the real go-smtp server wired as main.go does, and drives a live
SMTP session. Asserts: 550 for unknown RCPT, durable EML + row with
uid_next allocation, sha256 disk/db match, outbox event, blob dedup with
ref_count. Documents the counters gap (PLAN 6.1) as an explicit skip.
Phase: F1 validation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>