Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
main ▾

Modern-Apps.git / securemail / AGENTS.md

AGENTS.md8.0 KiBRenderedCodeRaw
1# AGENTS.md — securemail/ (':securemail')
2
3> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `securemail/` + allowed shared modules. Do not root-scan.
4
5_Install: ./install securemail (dev by default)._
6- Gradle: :securemail / dir: securemail/
7- Package roots present: ui, data, domain, platform, network, service
8- Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity before the key gate), Route.kt, Navigation.kt, ui/WearMainActivity.kt
9- Deps: :library:network, :library:biometric, :library:work, :library:room, :library:e2ee-openpgp, :library:wearlink, :library:log, Wear Compose (material + foundation)
10- Metadata: metadata_data/securemail.md (present)
11- Rust: no (native PGP via :library:e2ee-openpgp) / screenshotTest: yes
12
13## Overview
14**Purpose:** End-to-end-encrypted mail over the `mail.maemail.org` relay — OpenPGP identity per user, aliases, live WebSocket inbox with a periodic poll backstop. Requires internet.
15**Key features:**
16- PGP key generation/encrypt/decrypt/sign via the native Rust core (`Pgp` in `:library:e2ee-openpgp`, rPGP in `libe2ee_pgp.so`) — no BouncyCastle
17- Biometric-gated unlock: the Keystore-wrapped private key is unwrapped before any mail composes
18- Aliases, drafts, outbox retry, and WKD/VKS key lookup for external recipients
19**Architecture / data-flow:** `ui/` Compose screens → `platform/MailViewModel` (+ `AliasController`, `DraftsController`) → `data/` Room stores (`MailRepository`, `MailStore`, `InboundStore`) fed by `service/MailSocketService` over `network/MailSocket` (REST + WebSocket) and `platform/MailSyncWorker`; crypto in `domain/pgp/PgpCrypto` + `platform/crypto/KeyManager`. Unlike `email/`, there is no raw IMAP/SMTP and no `network.Networking` object — `network/MailSocket` is the sole network entry point.
20**Entry points + reading order:** `Route` (`Onboarding` / `Lock` / `Inbox(folder)` / `Composer` / `Reader(messageId)` / `Out` / `Settings` / `DeleteForeverDialog(messageIds, emptyTrash)` / `MessageDetailsDialog(messageId)`) → `MainActivity.kt` → `Navigation.kt` → `platform/MailViewModel.kt` → `data/MailRepository.kt` → `network/MailSocket.kt`.
21**Gotchas:**
22- `NetworkClient.init(this, TrustBundle.FIRST_PARTY)` must stay first in `onCreateBeforeContent` — `mail.maemail.org` is a pinned first-party host; WKD/VKS lookups for arbitrary external domains ride the platform trust store instead.
23- `MainActivity` is a `MaFragmentActivity` with `autoSetContent = false`: composition is deferred until `unlockIfReady` succeeds — don't set content before the key gate.
24- `:library:e2ee-openpgp` provides the PGP surface and securemail is its only consumer, so non-mail apps don't link rPGP — keep the PGP surface here, not in shared code.
25- `data/MailConfig` is the prefs owner (address token + onboarded flag, non-secret fields only, one process-wide DataStore); secrets live only in `platform/crypto/KeyManager`'s Keystore-wrapped prefs — never add secrets to `MailConfig`.
26- `MailSocketService` owns the live socket lifetime; `MailSyncWorker` is only a backstop poll — don't move delivery onto the worker.
27
28## Key files
29### Root — entry + navigation
30- com/vayunmathur/securemail/MainActivity.kt
31- com/vayunmathur/securemail/Navigation.kt
32- com/vayunmathur/securemail/Route.kt
33### data/ — Room stores + config
34- com/vayunmathur/securemail/data/MailDatabase.kt
35- com/vayunmathur/securemail/data/MailRepository.kt
36- com/vayunmathur/securemail/data/MailStore.kt
37- com/vayunmathur/securemail/data/InboundStore.kt
38- com/vayunmathur/securemail/data/Identities.kt
39- com/vayunmathur/securemail/data/SenderKeys.kt
40- com/vayunmathur/securemail/data/MailConfig.kt — sole prefs owner (non-secret)
41### domain/ — pure mail + PGP policy
42- com/vayunmathur/securemail/domain/mail/MailPolicy.kt
43- com/vayunmathur/securemail/domain/mail/AliasGenerator.kt
44- com/vayunmathur/securemail/domain/mail/KeyLookupPolicy.kt
45- com/vayunmathur/securemail/domain/mail/MimeCodec.kt
46- com/vayunmathur/securemail/domain/pgp/PgpCrypto.kt — `Pgp` (rPGP) wrapper surface
47### network/ — relay REST + WebSocket (sole network entry)
48- com/vayunmathur/securemail/network/MailSocket.kt
49### platform/ — ViewModel, controllers, key gate, sync
50- com/vayunmathur/securemail/platform/MailViewModel.kt
51- com/vayunmathur/securemail/platform/AliasController.kt
52- com/vayunmathur/securemail/platform/DraftsController.kt
53- com/vayunmathur/securemail/platform/OutboxRetry.kt
54- com/vayunmathur/securemail/platform/MailSyncWorker.kt
55- com/vayunmathur/securemail/platform/BootReceiver.kt
56- com/vayunmathur/securemail/platform/IntentState.kt
57- com/vayunmathur/securemail/platform/crypto/KeyManager.kt — Keystore-wrapped PGP private key
58### Watch experience (ui/ + data/ + sync/ + platform/)
59- com/vayunmathur/securemail/ui/WearMainActivity.kt — watch entry (WearShellActivity, exported=false)
60- com/vayunmathur/securemail/ui/WearRoute.kt, WearInboxListScreen.kt, WearMessageScreen.kt
61- com/vayunmathur/securemail/data/WearSecureMailStore.kt — watch metadata snapshot + pending ops
62- com/vayunmathur/securemail/sync/WearSecureMailSync.kt — phone metadata publish + op apply
63- com/vayunmathur/securemail/sync/WearLinkBridge.kt, WearWatchStatePublisher.kt, ConduitSyncTriggerReceiver.kt
64- com/vayunmathur/securemail/platform/FormFactor.kt — watch detection (FEATURE_WATCH)
65### service/ — live socket lifetime
66- com/vayunmathur/securemail/service/MailSocketService.kt
67### ui/ — inbox, reader, composer, onboarding
68- com/vayunmathur/securemail/ui/InboxScreen.kt
69- com/vayunmathur/securemail/ui/ReaderScreen.kt
70- com/vayunmathur/securemail/ui/ComposeScreen.kt
71- com/vayunmathur/securemail/ui/OnboardingScreen.kt
72- com/vayunmathur/securemail/ui/LockScreen.kt
73- com/vayunmathur/securemail/ui/OutScreen.kt
74- com/vayunmathur/securemail/ui/SettingsScreen.kt
75- com/vayunmathur/securemail/ui/NavigationEntries.kt
76- com/vayunmathur/securemail/ui/dialogs/DeleteForeverDialog.kt
77- com/vayunmathur/securemail/ui/dialogs/MessageDetailsDialog.kt
78
79## One APK, two form factors (phone + watch)
80Single merged APK (same applicationId/signing; no watch uses-feature, touchscreen not-required, standalone=false; `nativeAbis { armv7 = true }` for the PGP native lib on 32-bit watches). `platform/FormFactor` reads `PackageManager.FEATURE_WATCH`: `MainActivity` forwards watches to `ui/WearMainActivity` before `NetworkClient.init` and before any biometric/PGP unlock; the watch never unwraps a key.
81
82## Wear sync + security call (Watch conduit client)
83Protocol in `:library:wearlink` at `com.vayunmathur.library.wearlink.securemail.WearSecureMailProtocol`. **Decrypted content never leaves the phone**: PGP keys/passphrase stay phone-side, so the snapshot (`/securemail/snapshot`, 30 messages, ≤90,000 bytes) carries envelope metadata only (sender capped, date, read state, folder, hasDecryptedBody/unencrypted flags) — no decrypted subject, body or preview exists on the wire type. Phone publish via `sync/WearSecureMailSync` (INBOX previews, no decryption performed); watch persists metadata in `data/WearSecureMailStore`. The only watch op is mark read/unread (`/securemail/op`, DAO `setRead`, no decryption needed), pending until reflected. Triggers: conduit Connected, watch request (`/securemail/request-sync`), `sync/ConduitSyncTriggerReceiver` (CONDUIT signature permission). Transport is `WearLinkClientNode` (appId `securemail`); only the Watch conduit app holds Bluetooth permission.
84
85## Watch experience
86`ui/WearMainActivity` (WearShellActivity) routes `ui/WearRoute` (Inbox / Message(id)): metadata inbox (sender/time, unread bold) and metadata detail (sender/date/folder, decrypted-on-phone note, Mark read/unread, Open on phone last via `/securemail/open-on-phone` — the phone is the only read/decrypt path). Watch screenshots are `group="wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt` via `:securemail:metadata`.
87
88## Verify (this module only)
89```
90./gradlew :securemail:compileDevKotlin
91./gradlew :securemail:lint :securemail:lintVitalRelease :securemail:testDevUnitTest
92./gradlew :securemail:checkMetadata
93./gradlew :securemail:metadata
94```