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

Modern-Apps.git / email / AGENTS.md

AGENTS.md9.1 KiBRenderedCodeRaw
1# AGENTS.md — email/ (':email')
2
3> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `email/` + allowed shared modules. Do not root-scan.
4
5_Install: ./install email (dev by default)._
6- Gradle: :email / dir: email/
7- Package roots present: ui, data, platform, network, intents, widget
8- Entry files: MainActivity.kt, Route.kt, Navigation.kt
9- Deps: :library:room, :library:widgets, :library:network
10- Metadata: metadata_data/email.md (present)
11- Rust: no / screenshotTest: yes
12
13## Overview
14**Purpose:** A modern open-source email client with a unified inbox across multiple accounts. Requires internet.
15**Key features:**
16- Unified inbox over any IMAP/SMTP provider, with presets + OAuth for Gmail/Outlook/Yahoo/iCloud/Fastmail
17- Push mail over IMAP IDLE plus hourly poll for the rest; outbox retry, drafts, and snooze via WorkManager
18- Composer with inline images (HTML editor + CID spans) and an EML file viewer
19- Home-screen widget, rich notifications with actions, and assistant read/search intents
20**Architecture / data-flow:** `ui/` Compose screens → `platform/EmailViewModel` (+ `EmailManager`, send/draft action helpers) → `data/` Room stores (`*Dao`/`*Store` pairs + `EmailRepository`) fed by workers (`EmailSyncWorker`, `ImapIdleService`, `OutboxSendWorker`, `SnoozeWorker`) → `network/` raw IMAP/SMTP clients. `MainActivity.onCreateBeforeContent`: `NetworkClient.init(SYSTEM)` first, then widget previews, intent handling, hourly-sync schedule, outbox flush, IDLE start, and two one-time backfills.
21**Entry points + reading order:** `Route` (`MessageList` / `MessageThread` / `Composer` / `Outbox` / `Drafts` / `AddAccount` / `AddAccountForm` / `Settings` / `EmlViewer` / `UnsubscribeDialog` / `MessageDetailsDialog`) → `MainActivity.kt` → `Navigation.kt` → `ui/MainContent.kt` → `platform/EmailViewModel.kt` → `data/EmailRepository.kt`.
22**Gotchas:**
23- `NetworkClient.init(this, TrustBundle.SYSTEM)` must stay first in `onCreateBeforeContent` — mail servers need system CAs, not the first-party bundle
24- `DateMillisBackfill`/`PeekContentBackfill` are one-time migrations gated on `runIfNeeded`; skipping them breaks sort order and snippet previews
25- IDLE push is foreground-gated via `AppLifecycleTracker` — background delivery goes through the hourly worker + notifications, not the socket
26- Startup never crashes the first screen: constructing `EmailRepository` and `EmailViewModel` never builds the database (stores and `draftsActions` are lazy, DAO flows are acquired via a guard that falls back to an empty flow), `MainActivity.onCreateBeforeContent` steps run in isolation via `platform/StartupGuard` (catches `Throwable`, rethrows only cancellation), the backfills and IDLE start guard their own database access, and `EmailViewModel.accounts` degrades to an empty list (the Add Account gate) when the database will not build or open on the device
27- `network/imap/TrustAll.kt` exists for debug only; never widen its use
28- Upgrades from app versions before v2.6.0 start with a fresh local database (supported upgrade floor: Email DB v17; DB versions 1–16 open destructively, v17 onward migrates normally)
29- Platform backup never copies the raw SQLCipher DB or any credential: account passwords are sealed by the device-bound Keystore (`CredentialCrypto`) and cannot transfer, so `AppBackupAgent` backs up only the sanitized `EmailBackup` payload; restored accounts have empty credential fields, are skipped by sync/IDLE, and prompt for re-auth in Settings
30
31## Key files
32### Root — entry + navigation
33- com/vayunmathur/email/MainActivity.kt
34- com/vayunmathur/email/Navigation.kt
35- com/vayunmathur/email/Route.kt
36### data/ — Room stores + sync workers
37- com/vayunmathur/email/data/EmailModels.kt
38- com/vayunmathur/email/data/EmailDatabase.kt
39- com/vayunmathur/email/data/EmailAccountDao.kt
40- com/vayunmathur/email/data/EmailAccountStore.kt
41- com/vayunmathur/email/data/EmailMessageDao.kt
42- com/vayunmathur/email/data/EmailMessageStore.kt
43- com/vayunmathur/email/data/EmailOutboxDao.kt
44- com/vayunmathur/email/data/EmailOutboxStore.kt
45- com/vayunmathur/email/data/EmailQueryDao.kt
46- com/vayunmathur/email/data/EmailQueryStore.kt
47- com/vayunmathur/email/data/EmailRepository.kt
48- com/vayunmathur/email/data/EmailSettings.kt
49- com/vayunmathur/email/data/EmailSyncState.kt
50- com/vayunmathur/email/data/EmailSyncWorker.kt
51- com/vayunmathur/email/data/ImapIdleService.kt
52- com/vayunmathur/email/data/ImapIdleRetryWorker.kt
53- com/vayunmathur/email/data/OutboxSendWorker.kt
54- com/vayunmathur/email/data/SnoozeWorker.kt
55- com/vayunmathur/email/data/OutlookOAuth.kt
56- com/vayunmathur/email/data/ProviderPresets.kt
57- com/vayunmathur/email/data/CredentialCrypto.kt
58- com/vayunmathur/email/data/EmailBackup.kt — sanitized platform-backup payload (accounts/folders/blocked senders, no secrets) + `needsReauth()`
59- com/vayunmathur/email/data/DateMillisBackfill.kt
60- com/vayunmathur/email/data/PeekContentBackfill.kt
61### network/ — raw IMAP + SMTP clients
62- com/vayunmathur/email/network/imap/ImapClient.kt
63- com/vayunmathur/email/network/imap/RawImapConnection.kt
64- com/vayunmathur/email/network/imap/ImapWireIo.kt
65- com/vayunmathur/email/network/imap/ImapParser.kt
66- com/vayunmathur/email/network/imap/ImapFetchPipeline.kt
67- com/vayunmathur/email/network/imap/MimeParser.kt
68- com/vayunmathur/email/network/imap/MimeDecoding.kt — quoted-printable/charset/RFC2047/date/filename/multipart decoding extracted from MimeParser (MimeParser delegates)
69- com/vayunmathur/email/network/imap/MimeParserParts.kt
70- com/vayunmathur/email/network/imap/ImapAuthException.kt
71- com/vayunmathur/email/network/imap/TrustAll.kt — debug only
72- com/vayunmathur/email/network/smtp/SmtpClient.kt
73- com/vayunmathur/email/network/smtp/RawSmtpConnection.kt
74- com/vayunmathur/email/network/smtp/MimeBuilder.kt
75### platform/ — ViewModel, actions, notifications, lifecycle
76- com/vayunmathur/email/platform/EmailViewModel.kt
77- com/vayunmathur/email/platform/StartupGuard.kt — isolated best-effort startup steps (#939)
78- com/vayunmathur/email/platform/AppBackupAgent.kt — key/value backup agent: sanitized account payload + `email_settings` prefs; restored accounts prompt for the app password in Settings
79- com/vayunmathur/email/platform/EmailManager.kt
80- com/vayunmathur/email/platform/EmailUiContract.kt
81- com/vayunmathur/email/platform/EmailClientFlag.kt
82- com/vayunmathur/email/platform/EmailSendActions.kt
83- com/vayunmathur/email/platform/EmailDraftActions.kt
84- com/vayunmathur/email/platform/AiSummaryHelper.kt
85- com/vayunmathur/email/platform/EmailNotifications.kt
86- com/vayunmathur/email/platform/EmailNotificationActionReceiver.kt
87- com/vayunmathur/email/platform/AppLifecycleTracker.kt
88- com/vayunmathur/email/platform/BootReceiver.kt
89- com/vayunmathur/email/platform/EmlUtils.kt
90- com/vayunmathur/email/platform/IntentState.kt
91### ui/ — list, thread, composer, account flows
92- com/vayunmathur/email/ui/MainContent.kt
93- com/vayunmathur/email/ui/MessageListScreen.kt
94- com/vayunmathur/email/ui/MessageThreadScreen.kt — thread pane: strip + one open message, no outer scroller
95- com/vayunmathur/email/ui/ThreadMessageStrip.kt
96- com/vayunmathur/email/ui/MessageItem.kt — header / self-scrolling body / footer
97- com/vayunmathur/email/ui/MessageFooter.kt
98- com/vayunmathur/email/ui/FolderList.kt
99- com/vayunmathur/email/ui/DetailItem.kt
100- com/vayunmathur/email/ui/ComposerScreen.kt
101- com/vayunmathur/email/ui/ComposerHeader.kt
102- com/vayunmathur/email/ui/ComposerAttachments.kt
103- com/vayunmathur/email/ui/ComposerHelpers.kt
104- com/vayunmathur/email/ui/AttachmentItem.kt
105- com/vayunmathur/email/ui/composer/EmailHtmlEditor.kt
106- com/vayunmathur/email/ui/composer/EmailHtmlEditorController.kt
107- com/vayunmathur/email/ui/composer/EmailHtmlSerializer.kt
108- com/vayunmathur/email/ui/composer/EmailHtmlTagHandler.kt
109- com/vayunmathur/email/ui/composer/EmailHtmlInline.kt
110- com/vayunmathur/email/ui/composer/InlineImage.kt
111- com/vayunmathur/email/ui/composer/CidImageSpan.kt
112- com/vayunmathur/email/ui/DraftsContent.kt, OutboxContent.kt, SettingsContent.kt, EmlViewerContent.kt — stateless slices for previews
113- com/vayunmathur/email/ui/EmailDialogEntries.kt — `DialogPage()` entries for `UnsubscribeDialog` + `MessageDetailsDialog`
114- com/vayunmathur/email/ui/dialogs/UnsubscribeDialogContent.kt — stateless unsubscribe confirmation
115- com/vayunmathur/email/ui/dialogs/MessageDetailsDialogContent.kt — stateless message-details sheet
116- com/vayunmathur/email/ui/NavigationEntries.kt
117- com/vayunmathur/email/ui/OutboxScreen.kt
118- com/vayunmathur/email/ui/EmlViewerScreen.kt
119- com/vayunmathur/email/ui/AddAccountScreen.kt
120- com/vayunmathur/email/ui/AddAccountSection.kt
121- com/vayunmathur/email/ui/AddAccountInstructionsCard.kt
122- com/vayunmathur/email/ui/OAuthActivity.kt
123- com/vayunmathur/email/ui/SettingsScreen.kt
124- com/vayunmathur/email/ui/EmailUiHelpers.kt
125### intents/ — assistant IPC
126- com/vayunmathur/email/intents/GetRecentIntent.kt
127- com/vayunmathur/email/intents/SearchIntent.kt
128- com/vayunmathur/email/intents/EmailDataMapper.kt
129### widget/ — unified-inbox home widget
130- com/vayunmathur/email/widget/EmailWidget.kt — includes `EmailWidgetReceiver` (one widget, one file)
131
132## Verify (this module only)
133```
134./gradlew :email:compileDevKotlin
135./gradlew :email:lint
136./gradlew :email:checkMetadata
137```