Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / securemail / AGENTS.md
| 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, Route.kt, Navigation.kt |
| 9 | - Deps: :library:network, :library:biometric, :library:work, :library:room, :library:e2ee-openpgp |
| 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 | ### service/ — live socket lifetime |
| 59 | - com/vayunmathur/securemail/service/MailSocketService.kt |
| 60 | ### ui/ — inbox, reader, composer, onboarding |
| 61 | - com/vayunmathur/securemail/ui/InboxScreen.kt |
| 62 | - com/vayunmathur/securemail/ui/ReaderScreen.kt |
| 63 | - com/vayunmathur/securemail/ui/ComposeScreen.kt |
| 64 | - com/vayunmathur/securemail/ui/OnboardingScreen.kt |
| 65 | - com/vayunmathur/securemail/ui/LockScreen.kt |
| 66 | - com/vayunmathur/securemail/ui/OutScreen.kt |
| 67 | - com/vayunmathur/securemail/ui/SettingsScreen.kt |
| 68 | - com/vayunmathur/securemail/ui/NavigationEntries.kt |
| 69 | - com/vayunmathur/securemail/ui/dialogs/DeleteForeverDialog.kt |
| 70 | - com/vayunmathur/securemail/ui/dialogs/MessageDetailsDialog.kt |
| 71 | |
| 72 | ## Verify (this module only) |
| 73 | ``` |
| 74 | ./gradlew :securemail:compileDevKotlin |
| 75 | ./gradlew :securemail:lint |
| 76 | ./gradlew :securemail:checkMetadata |
| 77 | ``` |