mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-06-26 01:42:42 +08:00
refactor: modularize IMAP server with fixes and E2E tests - Modularize IMAP server into imap_server, imap_mailbox, imap_message, imap_http_client, parse_email, config, models - Support dual login: JWT token and address+password via backend - Add STARTTLS support with configurable TLS cert/key - Fix FETCH/STORE returning UID instead of sequence number (RFC 3501) - Implement IMessageFile.open() for correct BODY[] raw MIME delivery - Add UIDNEXT to SELECT response via _cbSelectWork override - Use per-restart UIDVALIDITY to force client resync - Pass raw MIME to SimpleMessage for accurate RFC822.SIZE - Fix SENT mailbox returning empty source - Handle CREATE command gracefully for Thunderbird compatibility - Add IMAP E2E tests: auth, LIST, SELECT, STATUS, FETCH, SEARCH, STORE, UID FETCH, BODY[] integrity, size, seq numbers, SENT mailbox - Add SMTP E2E tests using nodemailer: send plain/HTML, auth failure, sendbox verification - Add sendTestMail helper using admin/send_mail Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
E2E Tests
End-to-end tests for Cloudflare Temp Email using Playwright and Mailpit, fully containerized with Docker Compose.
Prerequisites
- Docker and Docker Compose
Quick Start
cd e2e
# Build, start all services, run tests, and exit
npm test
# Clean up containers and volumes
npm run test:down
npm test runs docker compose up --build, which:
- Starts Mailpit (SMTP on :1025, HTTP API on :8025)
- Builds and starts the Worker (wrangler dev on :8787)
- Builds and starts the Frontend (vite dev on :5173)
- Builds and runs the E2E runner (Playwright), which waits for services, initializes the DB, and runs all tests
The exit code reflects the test result.
Test Structure
| Project | Directory | What it tests |
|---|---|---|
api |
tests/api/ |
Worker API endpoints — health check, address CRUD, send mail via SMTP |
browser |
tests/browser/ |
Frontend UI — login, inbox view, reply with HTML, XSS sanitization |
Services
| Service | Container | Port | Purpose |
|---|---|---|---|
| Mailpit SMTP | mailpit |
1025 | Captures outgoing emails |
| Mailpit HTTP | mailpit |
8025 | API to verify captured emails |
| Worker | worker |
8787 | Backend API with E2E config |
| Frontend | frontend |
5173 | Vue frontend dev server |
Test Results
Test results and HTML reports are exported via volumes:
e2e/test-results/— test artifactse2e/playwright-report/— HTML report
Configuration
The E2E worker uses fixtures/wrangler.toml.e2e with:
E2E_TEST_MODE = true— enables test seed endpointDISABLE_ADMIN_PASSWORD_CHECK = true— allows unauthenticated admin callsDEFAULT_SEND_BALANCE = 10— allows sending without admin approval- SMTP pointed at Mailpit container (
mailpit:1025)