#41
Add IMAP and SMTP mail accounts
Problem
Redakt's full mail client supported Gmail, but issue #5 still lacked a way to connect other email providers.
Result
- Adds encrypted IMAP/SMTP accounts with Fastmail, Yahoo, iCloud, and custom server presets.
- Supports mailbox browsing, search, folders, drafts, attachments, flags, moves, and sending, including appending sent mail to the provider's Sent folder.
- Validates server settings before saving and blocks private or internal network targets.
- Adds the account settings UI, database migration, documentation, and privacy disclosures.
Validation
pnpm test(174 passing)pnpm build- Focused ESLint for all changed TypeScript and TSX files
pnpm exec drizzle-kit checkgit diff --check- Desktop and 320px browser checks, including accessible labels and horizontal-overflow verification
Repository-wide pnpm lint continues to report the two pre-existing @typescript-eslint/no-require-imports errors in babel.config.js and postcss.config.js; changed source files pass lint.
Known limitations
- The generic connector uses username and app-password authentication; OAuth-only providers need provider-specific connectors. Gmail continues to use its native OAuth integration.
- IMAP refreshes when mailbox views load or refresh rather than using a long-running IDLE or push connection.
- Message bodies and attachments remain with the provider and are not imported into Postgres.
- IMAP messages are displayed individually rather than reconstructed into provider-specific conversation threads.
Closes #5.
Summary
Reviewed the full diff against
2f48341..f84e0dd(23 files, +2430/-31), focused on the IMAP/SMTP connector:lib/imap/config.ts,lib/imap/provider.ts,lib/imap/mime.ts, the account API routes,lib/data/mail-accounts.ts,lib/mail/get-provider.ts/accounts.ts, the settings UI, and the schema migration.No blocking issues found. Specifically checked and confirmed sound:
resolvePublicMailHostinlib/imap/config.ts): rejects IP literals and bare hostnames, resolves via DNS, rejects if any returned address is non-unicast (blocks private/loopback/link-local/ULA/reserved), and — importantly — connects using the resolved IP literal ashostwithservernameset separately for TLS SNI, so there's no DNS-rebinding TOCTOU between the check and the actual connection. This same check runs both at connect-time (connectImapAccount) and on every subsequent use (ImapProvider.withClient/send), so a host can't be validated once and swapped later.findStoredMailAccount,listStoredMailAccounts, delete) are scoped byuserId, andconnectImapAccountonly reuses an existing row ID after filtering the caller's own accounts by email — no path lets one user target another user'smailAccountsrow.encryptSecret/decryptSecretkeyring, andstoredMailAccountToDescriptor(the shape returned to the client/API) never includesencryptedPassword.dangerouslySetInnerHTMLintroduced; React escaping covers the new settings form and account list rendering.Non-blocking follow-up
lib/imap/config.tsadds the SSRF allowlist (resolvePublicMailHost,publicAddress,HOST_PATTERN) and input normalization (normalizeImapAccountInput) — the most security-sensitive new logic in this PR — but no unit tests were added for either (onlylib/imap/mime.test.mjswas added, covering MIME parsing/ID encoding). Given this function is the sole barrier against an authenticated user pointing the server at internal infrastructure, I'd want direct coverage for: private/loopback/link-local rejection, mixed public+private A/AAAA records, IP-literal hostnames, and the "no dot" bare-hostname case, before this logic is refactored by someone unfamiliar with the threat model.Verification performed: read the full diff, cross-referenced
getMailProvider,saveMailAccount/findStoredMailAccountscoping, and the account descriptor serialization to confirm no credential leakage or cross-user access path.