Persist per-server enablement, search enabled servers, and require an explicit publication target. Update documentation and tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
117 lines
6.6 KiB
Markdown
117 lines
6.6 KiB
Markdown
# 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.cjs` is 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.cjs` exposes a minimal API to the renderer through `window.daybreakMail` and `window.pgpPrepareSend`.
|
|
|
|
### Renderer UI
|
|
|
|
The browser UI is rendered from the web assets in the root and `www/` folders:
|
|
|
|
- `index.html` and the shared shell files define the layout and global state.
|
|
- `app.js`, `mail-ui.js`, `account-ui.js`, `dav-ui.js`, `pgp-ui.js`, and `pgp-mail-ui.js` handle 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.enc` stores connected IMAP/SMTP accounts and their settings.
|
|
- `dav-accounts.enc` stores CalDAV/CardDAV credentials and server config.
|
|
- `pgp-keys.enc` stores 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:
|
|
|
|
1. The renderer asks the main process for a folder sync or inbox refresh.
|
|
2. The main process opens an IMAP connection and fetches only the requested subset or page.
|
|
3. Sync results are written back into the account state and sent to the renderer via IPC (`mail:sync-update`).
|
|
4. 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.cjs` stores contacts, trust, key material, and settings.
|
|
- `desktop/pgp-mail.cjs` handles message detection, decryption, verification, encryption, and signature checks.
|
|
- `desktop/pgp-keyservers.cjs` implements bounded HTTPS lookup and publication for VKS and HKP-compatible servers.
|
|
- `desktop/main.cjs` bridges 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 enablement is persisted in encrypted OpenPGP settings; all servers default to disabled, including custom servers already configured by older versions. The main process enforces enabled status for both lookup and publication. A lookup queries all enabled servers, reports partial failures, and merges duplicate fingerprints while retaining source names. The user chooses one enabled server as the publication target. 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 naming the destination 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:win` for Windows installer/portable builds
|
|
- `npm run dist:linux` for 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.
|