elektromail 0.1.1

A minimal, Rust-based IMAP + SMTP mail server for local development and testing
Documentation
# Epics: Rust Mini Mail Server (IMAP + SMTP)

This file captures implementation epics and detailed acceptance criteria that are intentionally out of scope for the PRD.

---

## Epic: HTTP Control Plane (Optional/Future)

A lightweight HTTP API for advanced test scenarios. Most use cases are served by environment variables + standard IMAP/SMTP clients.

### Potential Endpoints
- `POST /reset` - Clear all state (users, mailboxes, messages) in < 50 ms
- `POST /users` - Create user dynamically
- `POST /inject` - Inject test email directly (bypass SMTP)
- `GET /messages/{user}/{mailbox}` - List messages for debugging

### Acceptance Criteria (if implemented)
- Reset clears all state in < 50 ms
- Endpoints return JSON responses
- Auth optional (disabled by default for dev/test)

**Note:** This epic is deferred. Current test approach uses environment variables for user setup and standard protocol clients for interaction.

---

## Out of Scope: RFC Compliance Testing

RFC 9051 compliance testing is a **separate concern** from the mail server itself.

A reusable test harness for validating any IMAP server lives in `/tests/rfc9051/`. This test suite:
- Can run against elektromail or any external IMAP server
- Tests RFC 9051 compliance by command and state
- Is documented in [rfc9051-compliance-testing.md]rfc9051-compliance-testing.md

This separation allows:
1. elektromail to focus on being a lightweight dev/test server
2. The RFC test suite to be reusable for validating other implementations

---

## Epic: Core SMTP Server (ESMTP + Submission)
- Implement SMTP command parsing and session state.
- Support `EHLO/HELO`, `MAIL FROM`, `RCPT TO`, `DATA`, `RSET`, `NOOP`, `QUIT`.
- Enforce size limits and basic recipient validation.
- Store received messages in the mail store with deterministic internal dates.

## Epic: Core IMAP Server (IMAP4rev1)
- Implement IMAP command parsing and session state.
- Support MVP command set: `CAPABILITY`, `LOGIN`, `LIST`, `SELECT`, `FETCH`, `UID FETCH`, `STORE`, `UID STORE`, `SEARCH`, `APPEND`, `COPY`, `EXPUNGE`, `LOGOUT`.
- Implement flags and per-mailbox UID mapping semantics.
- Provide stable ordering for `FETCH` and `SEARCH` results.

## Epic: Storage Layer (SQLite + In-Memory)
- Implement storage trait with SQLite backend as default.
- Support in-memory mode with fast reset.
- Persist RFC 5322 bytes and minimal metadata.
- Ensure atomic UID allocation and flag updates via transactions.

## Epic: Users, Mailboxes, and Auth
- Create and manage users with simple auth (test mode).
- Default mailboxes (`INBOX`, optional `Sent`, `Drafts`, `Trash`).
- Implement basic access control (user mailbox isolation).

## Epic: Determinism & UID/Flag Semantics
- Monotonic per-mailbox UID allocation.
- Stable ordering by `internal_date` then UID.
- Deterministic behavior across repeated runs and resets.

## Epic: Extensions & Capabilities (MVP+)
- IMAP: `UIDPLUS`, `LITERAL+` or `LITERAL-`, optional `IDLE`.
- SMTP: `SIZE`, optional `AUTH PLAIN`, optional `STARTTLS` (dev/demo).
- Accurate `CAPABILITY` / `EHLO` responses reflecting enabled features.

## Epic: Modes, Config, and Lifecycle
- Test mode defaults (loopback-only, no TLS, in-memory).
- Dev/demo mode (optional TLS, SQLite persistence, logging).
- Configurable ports, size limits, users, and storage options.

## Epic: TLS & Security Controls (Optional)
- STARTTLS for SMTP and IMAP (self-signed in dev/demo).
- Clear warnings for insecure configs.
- Disable open relay by default.

## Epic: Observability & Diagnostics
- Structured logging (feature-gated).
- Minimal metrics (connections, messages, errors).
- Debug tooling hooks for test flakiness triage.

## Epic: CLI/Binary Packaging
- Standalone binary for local dev/demo.
- CLI flags for mode, ports, storage path, and TLS.
- Graceful shutdown on SIGINT/SIGTERM.

## Epic: Test Suite & Conformance
- Unit tests for SMTP/IMAP parsing and state machines.
- Integration tests for SMTP->IMAP flows.
- Determinism tests (UID/order/flags).
- Resource tests for startup time and memory usage.

---

## Suggested Delivery Sequence (Epics)

### Completed ✓
1. ~~Storage Layer (In-Memory)~~
2. ~~Users, Mailboxes, and Auth~~
3. ~~Core SMTP Server (ESMTP + Submission)~~
4. ~~Core IMAP Server (IMAP4rev1)~~
5. ~~Determinism & UID/Flag Semantics~~
6. ~~Modes, Config, and Lifecycle~~
7. ~~Extensions & Capabilities (MVP+)~~
8. ~~TLS & Security Controls (IMAP STARTTLS)~~
9. ~~CLI/Binary Packaging~~

### Remaining
10. Storage Layer (SQLite persistence)
11. SMTP STARTTLS
12. Observability & Diagnostics (structured logging, metrics)
13. HTTP Control Plane (optional/future)

### Dependencies & Notes
- SQLite persistence builds on existing in-memory storage trait.
- SMTP STARTTLS mirrors existing IMAP STARTTLS implementation.
- HTTP Control Plane is optional; most use cases work with env vars + protocol clients.
- Observability can be added incrementally without blocking other work.