120 lines
8.5 KiB
Markdown
120 lines
8.5 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. On Windows, its notification-area tray icon uses the packaged multi-resolution application icon and provides Open and Quit actions. Packaged startup repairs an existing per-user Start Menu shortcut to target the launched app and use its icon, keeping taskbar pins associated with the matching AppUserModelID.
|
|
- `desktop/preload.cjs` exposes the narrow platform API through `window.daybreakMail`. Renderer-to-renderer contracts are grouped under `window.epMailState`, `window.epMailShell`, and `window.epMailFeatures`.
|
|
|
|
### Renderer UI
|
|
|
|
The browser UI is rendered from canonical web assets in the repository root; `www/` is generated for Capacitor:
|
|
|
|
- `index.html` defines the classic-script bootstrap order. `renderer-state.js` exposes shared state as `window.epMailState` without legacy unnamespaced aliases.
|
|
- `app.js` publishes `window.epMailShell`; the mail, productivity, DAV, and PGP mail modules publish explicit APIs under `window.epMailFeatures`. PGP key management extends the productivity Preferences UI through that API.
|
|
- Renderer feature implementations are locally scoped. The ordered classic-script bootstrap remains a compatibility constraint for desktop and Capacitor, and is covered by bootstrap and combined-script tests.
|
|
- The renderer is intentionally thin: it requests actions and displays data, while mail-protocol and cryptographic network work stays in the main process. The reader makes direct HTTPS image requests only after explicit per-message approval.
|
|
|
|
### 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 the desktop `mail:send` IPC or the Android `EpMail.send` plugin with message fields and selected attachment bytes
|
|
- the native send path resolves the account, checks sender settings, builds multipart MIME, and on desktop applies OpenPGP encryption/signing to the body and attachments before sending
|
|
- the message is either transmitted immediately or queued as an offline send when connectivity is unavailable; local draft attachments are persisted with draft content
|
|
|
|
The renderer sends file bytes rather than local paths. OpenPGP messages are encrypted before offline queueing so the outbox contains ciphertext instead of plaintext message or attachment content.
|
|
|
|
## 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.
|
|
- Replacement-key operations are also confirmed in the main process; tests assert cancellation does not update the contact key.
|
|
- 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.
|
|
- Incoming HTML is sanitized in the renderer before insertion. HTTPS image URLs are kept in inert data attributes; only a per-message user action assigns image sources, and reopening the message resets that approval. HTTP images are rejected to preserve Android's cleartext-traffic protection. The CSP allows HTTPS images; scripts, frames, forms, and remote connections remain blocked.
|
|
- 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/ipc/pgp.cjs` bridges those services into the Electron IPC API; `desktop/main.cjs` wires the services and registrars together.
|
|
|
|
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 native mail service and passed to the renderer as plain text, bounded HTML alternatives, links, and attachment metadata. HTML is allowlist-sanitized before display; HTTPS image requests remain inert until explicitly enabled for the current message view.
|
|
- 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.
|