- Add VKS and HTTPS HKP lookup and publication with bounded, validated requests. - Add desktop key-server settings, lookup/import flow, and per-publication native confirmation. - Keep discovered keys untrusted and update architecture, encryption, and user documentation. - Add mocked server protocol and key-store tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
6.4 KiB
Architecture
This project has a layered architecture: a desktop Electron shell, a browser-rendered mail interface, platform-specific storage and sync adapters, and a separate Android Capacitor wrapper. The design keeps user state and credentials in the OS keyring, pushes IMAP/SMTP work into the main process, and exposes only a narrow IPC surface to the renderer.
1. Runtime layout
Desktop shell
desktop/main.cjsis the privileged process.- It owns account storage, mail sync, IMAP/SMTP connectivity, DAV sync, and OpenPGP key handling.
- It can show native dialogs, notifications, and system prompts.
desktop/preload.cjsexposes a minimal API to the renderer throughwindow.daybreakMailandwindow.pgpPrepareSend.
Renderer UI
The browser UI is rendered from the web assets in the root and www/ folders:
index.htmland the shared shell files define the layout and global state.app.js,mail-ui.js,account-ui.js,dav-ui.js,pgp-ui.js, andpgp-mail-ui.jshandle page flow, compose/read views, account setup, and encryption UX.- The renderer is intentionally thin: it requests actions and displays data, but the actual cryptographic and network work stays in the main process.
Android client
The Android app reuses the web UI in a Capacitor shell (android/, capacitor.config.json).
- The same browser UI runs inside the Android app.
- Native Android services handle background sync, notification behavior, and secure storage.
- The desktop and Android implementations intentionally share the same mail and account model so the feature surface stays aligned.
2. Core responsibilities
Mail and account state
The main process owns the canonical account model and persists it in an encrypted store:
mail-account.encstores connected IMAP/SMTP accounts and their settings.dav-accounts.encstores CalDAV/CardDAV credentials and server config.pgp-keys.encstores OpenPGP keys and trust data.
All three stores are wrapped with Electron safeStorage where available. Linux checks explicitly reject the insecure basic_text backend before credentials or keys are persisted.
Mail sync pipeline
The desktop app follows a background sync model:
- The renderer asks the main process for a folder sync or inbox refresh.
- The main process opens an IMAP connection and fetches only the requested subset or page.
- Sync results are written back into the account state and sent to the renderer via IPC (
mail:sync-update). - Periodic background sync and IDLE watchers reduce polling and keep new-mail notifications timely.
A generation counter invalidates stale sync jobs when accounts are edited or removed, and concurrent syncs are prevented to avoid overlapping IMAP traffic.
Message send path
The send flow is also centralized in the main process:
- the renderer calls
mail:send - the main process resolves the account, checks the sender settings, and applies OpenPGP encryption/signing before sending
- the message is either transmitted immediately or queued as an offline send when connectivity is unavailable
This prevents the renderer from silently bypassing critical security checks or storing plaintext in outbox data.
3. Security boundary
The current architecture takes a strict trust split:
- renderer: UI, user interaction, local conveniences
- main process: network access, cryptographic operations, permission prompts, OS secure storage
This boundary is important for encryption and safety checks:
- OpenPGP key selection and trust updates are confirmed in the main process.
- Key-server lookup results never elevate trust; only the public key is sent during a separately confirmed publication.
- Send-time downgrade checks happen in the main process rather than only in UI logic.
- External links open only after a native confirmation dialog.
- Credentials and private keys are stored with the OS keyring, not in plain JSON files.
4. OpenPGP subsystem
The OpenPGP implementation is split into focused modules:
desktop/pgp-keystore.cjsstores contacts, trust, key material, and settings.desktop/pgp-mail.cjshandles message detection, decryption, verification, encryption, and signature checks.desktop/pgp-keyservers.cjsimplements bounded HTTPS lookup and publication for VKS and HKP-compatible servers.desktop/main.cjsbridges those services into the Electron IPC API.
This keeps the cryptographic logic separate from the UI and gives the app a single place to enforce trust rules, passphrase checks, and recipient validation.
Key-server searches and publication requests are initiated from Settings and resolved by the main process. The renderer selects a configured server by ID rather than supplying an arbitrary request URL. Custom HTTPS endpoints require a native confirmation when added; redirects and oversized responses are rejected. Returned keys are validated and remain untrusted until the user verifies their fingerprints out of band. Publishing sends only public key material and requires a native confirmation for each publication.
5. Data flow patterns
- Account setup and edits flow from the UI into IPC, then into the encrypted main-process storage.
- Mail content is fetched by the main process and served to the renderer in a sanitized, parsed form.
- Attachments, decrypted bodies, and external links are all checked before user-visible actions are allowed.
- Search, folder listing, and draft operations reuse the same account model across both desktop and Android versions.
6. Release and packaging model
The project packages multiple platforms from the same codebase:
npm run dist:winfor Windows installer/portable buildsnpm run dist:linuxfor Linux AppImage and Debian builds- Android builds via Capacitor (
npm run android:apk)
The app version is managed through package metadata and the Electron build config in package.json.
7. Key architectural principles
- Keep privileged operations in the main process.
- Keep security rules in trusted code rather than the UI.
- Store secrets in OS-backed secure storage whenever the platform supports it.
- Share the same account and sync model between desktop and Android where possible.
- Treat mail encryption and secure key handling as first-class product features, not optional extras.
This architecture is intentionally built for a mail client that must handle privacy-sensitive data, background sync, and cross-platform parity without exposing the network or crypto stack to the renderer.