How hong-a-debug/hgmail works
This Cloudflare Workers email system receives and filters inbound mail, stores messages and attachments, and serves a role-aware web inbox. Users can register, sign in, read and delete mail, and compose or reply; administrators additionally manage settings and registration codes. The main runtime entry point coordinates these workflows with parsing, authentication, storage, attachment handling, and Resend. The README documents PWA/mailto support and automatic replies. Some route and UI details are unsampled, so those connections are shown only where documentation supports them.
Main entry points: index.ts Worker routes · admin.ts Admin settings · attachment.ts Attachment handling · template.html Inbox and PWA
Components 16
Worker runtime
- Worker routes
src/index.ts - Inbox and PWA
src/template.html
Mail handling
- Mail parser and filter
src/email-parser.ts - PostalMime
- Attachment handling
src/attachment.ts - Resend client
src/resend-client.ts
Accounts and administration
- Users and sessions
src/auth.ts - Admin settings
src/admin.ts - SHA-256 utility
src/utils.ts
Storage and delivery
- Email KV
- User KV
- Attachment R2
- Resend service
Other components
- Incoming sender
- Inbox user
- Email Routing
Connections 18
- Incoming sender → Email Routing: sends mail
README.md - Email Routing → Worker routes: routes mail
README.md - Inbox user → Inbox and PWA: uses inbox
README.md - Inbox and PWA → Worker routes: calls API
README.md - Worker routes → Mail parser and filter: parses mail
src/index.ts - Mail parser and filter → PostalMime: parses MIME
src/email-parser.ts - Worker routes → Email KV: stores mail
src/index.ts - Worker routes → Attachment handling: saves attachments
src/index.ts - Attachment handling → Attachment R2: reads and writes
src/attachment.ts - Worker routes → Users and sessions: manages sessions
src/index.ts - Users and sessions → User KV: reads and writes
src/auth.ts - Worker routes → Admin settings: handles settings
src/index.ts - Admin settings → User KV: stores settings
src/admin.ts - Admin settings → SHA-256 utility: hashes codes
src/admin.ts - Worker routes → Resend client: sends mail
src/index.ts - Resend client → Resend service: submits messages
src/resend-client.ts - Worker routes → Email KV: deletes mail
src/index.ts - Worker routes → Attachment handling: deletes attachments
src/index.ts