8.6 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. 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.cjsexposes the narrow platform API throughwindow.daybreakMail. Renderer-to-renderer contracts are grouped underwindow.epMailState,window.epMailShell, andwindow.epMailFeatures.
Renderer UI
The browser UI is rendered from canonical web assets in the repository root; www/ is generated for Capacitor:
index.htmldefines the classic-script bootstrap order.renderer-state.jsexposes shared state aswindow.epMailStatewithout legacy unnamespaced aliases.app.jspublisheswindow.epMailShell; the mail, productivity, DAV, and PGP mail modules publish explicit APIs underwindow.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.encstores connected IMAP/SMTP accounts, settings, and desktop OAuth tokens; OAuth refresh tokens never enter the renderer API.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 the desktop
mail:sendIPC or the AndroidEpMail.sendplugin 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.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/ipc/pgp.cjsbridges those services into the Electron IPC API;desktop/main.cjswires 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: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.