5 Commits

Author SHA1 Message Date
a60303e7b4 fix: guard folder rename against system folders, empty names, and dupes
PUT /api/v1/mailboxes/:id/folders/:id had no validation at all: any caller
could rename a system folder (inbox, sent, draft, archive, trash, spam) to
anything, rename it to an empty string, or collide its name with another
folder and trigger an unhandled SQLite UNIQUE-constraint exception.
deleteFolder already protected system folders via is_deletable -- give
updateFolder the same guard, reject empty names, and turn the UNIQUE
collision into a clean 409 instead of a 500.

Also notes that Cloudflare R2/AI/Durable Object infra is now actually
provisioned and the Worker is live at
https://agentic-inbox.subasiarhan3.workers.dev (fails closed pending the
owner-only Access + domain/Email Routing setup).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-22 03:48:31 +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
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