6 Commits

Author SHA1 Message Date
b5e772f51c feat: replace Cloudflare Access gate with Scribase owner-only auth
Cloudflare Access was permanently blocking this Worker (500 Cloudflare
Access must be configured in production): Zero Trust was never enabled
on the account and no available credential had Access-write scope.
Instead of waiting on that credential, access control now lives in code
against Scribase (this portfolio's self-hosted, Supabase-compatible
auth backend): a request is let through only if its Scribase access
token resolves to the exact OWNER_EMAIL account.

- workers/lib/scribase-auth.ts: token extraction, remote verification
  via GET /auth/v1/user, sign-in/refresh/sign-out via the password and
  refresh_token grants, with 25 unit tests.
- workers/lib/login-page.ts: dependency-free HTML sign-in page.
- workers/app.ts: new middleware (fail-closed on missing config, silent
  refresh-token retry, uniform 401 for API/MCP callers vs redirect for
  HTML), /login (rate-limited via a native Workers ratelimits binding)
  and /logout (also revokes the session server-side) routes. Removes
  the old jose/JWKS Cloudflare Access check entirely.
- wrangler.jsonc, .dev.vars.example, workers/types.ts, README.md:
  SCRIBASE_URL/SCRIBASE_ANON_KEY/OWNER_EMAIL replace
  POLICY_AUD/TEAM_DOMAIN; jose dropped from package.json.

Reviewed by code-reviewer and security-reviewer subagents; every
MEDIUM/HIGH finding fixed. Deployed and verified live: the Worker now
fails closed with the new Scribase message instead of the old
Cloudflare one. Provisioning the actual Scribase project is blocked on
a one-time $1 card check on the Scribase org (owner-only payment
action) -- see NOTES.md and ~/products/plans/agentic-inbox.md.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-24 17:10:54 +03:00
f2953ade9b feat: wire up vacation auto-reply and inbound forwarding settings
Mailbox settings already had forwarding{enabled,email} and
autoReply{enabled,subject,message} in the data model (set via the API),
but receiveEmail() never read them -- they were stored and silently
ignored. Add workers/lib/auto-respond.ts: maybeForwardEmail() sends a
copy of inbound mail to the configured address, and maybeSendAutoReply()
sends the configured vacation-responder reply once per thread per 24h
(enforced by new MailboxDO.shouldSendAutoReply, backed by DO storage so
it's wiped by purgeAllData() on mailbox delete). Both skip automated
senders/RFC 3834 Auto-Submitted messages and self-loops to avoid
auto-responder ping-pong. 14 new tests, full suite + typecheck pass.
2026-10-21 18:09:07 +03:00
0aac677af2 fix: purge DO data + R2 attachments on mailbox delete, fix draft-save ordering
Deleting a mailbox only removed its R2 settings file; the mailbox's
Durable Object (keyed by email address via idFromName, so a mailbox
recreated with the same address resolves to the same DO) kept every
email and attachment forever, silently resurrecting a "deleted"
mailbox's full history. Add MailboxDO.purgeAllData() to wipe the DO's
storage via storage.deleteAll() and return attachment keys for R2
cleanup, chunked at 1000 keys per R2Bucket.delete() call.

Also fix the drafts autosave endpoint: it deleted the superseded draft
before creating the new one, so a failure in createEmail() (DO
unavailable, storage error) silently lost the user's latest edits with
nothing left to recover. Create-then-delete means the same failure
just leaves a harmless duplicate instead of losing data.

Adds chunkArray() + tests; all 18 vitest tests and typecheck pass.
2026-10-21 15:44:16 +03:00
3548b394ab fix: carry original attachments over when forwarding an email
The web UI has no attachment-upload control, so Forward always sent the
new message with an empty attachments list — any attachment on the
original email was silently dropped instead of being included, unlike
every real email client. Copy the original email's R2-stored
attachments to the forwarded message's id and include them both in the
outgoing send and the stored Sent-folder copy.

Added workers/lib/attachments.test.ts (RED before the copyAttachments
implementation, GREEN after).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-21 03:39:51 +03:00
90234d6437 fix: chunk long search values to avoid DO SQLite LIKE pattern limit
MailboxDO#buildSearchConditions wrapped the query/from/to/subject
search filters directly as `%value%` LIKE patterns. Durable Object
SQLite rejects LIKE patterns above roughly 50 characters with an HTTP
500 (confirmed empirically: a 48-char value -> 50-char pattern
succeeds, a 49-char value -> 51-char pattern 500s) — so any search
long enough, including a user searching by a long exact subject,
crashed the search endpoint instead of returning results or a
validation error.

Split search values longer than 48 characters into <=48-char chunks
before wildcarding, AND the per-chunk LIKE conditions together, so no
single bound pattern can exceed the limit. Long values degrade to an
"all chunks present" match rather than 500ing. Extracted into
workers/lib/like-search.ts as pure, independently testable helpers,
with unit tests covering the chunk boundary (incl. the 49-char value
from the original report) and multi-column conditions.

Also adds vitest (previously absent from this repo) with a standalone
vitest.config.ts, since the project's main vite.config.ts loads the
Cloudflare Workers runtime plugin which isn't needed for, and breaks
under, plain unit tests of pure logic.

Fixes cloudflare/agentic-inbox#36.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-20 15:50:25 +03:00
Thomas Gauvin
cff1a79a39 Agentic Inbox: self-hosted email client with AI agent on Cloudflare Workers 2026-04-16 00:54:30 -04:00