# AGENTS.md — email/ (':email') > Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `email/` + allowed shared modules. Do not root-scan. _Install: ./install email (dev by default)._ - Gradle: :email / dir: email/ - Package roots present: ui, data, platform, network, intents, widget - Entry files: MainActivity.kt, Route.kt, Navigation.kt - Deps: :library:room, :library:widgets, :library:network - Metadata: metadata_data/email.md (present) - Rust: no / screenshotTest: yes ## Overview **Purpose:** A modern open-source email client with a unified inbox across multiple accounts. Requires internet. **Key features:** - Unified inbox over any IMAP/SMTP provider, with presets + OAuth for Gmail/Outlook/Yahoo/iCloud/Fastmail - Push mail over IMAP IDLE plus hourly poll for the rest; outbox retry, drafts, and snooze via WorkManager - Composer with inline images (HTML editor + CID spans) and an EML file viewer - Home-screen widget, rich notifications with actions, and assistant read/search intents **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. **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`. **Gotchas:** - `NetworkClient.init(this, TrustBundle.SYSTEM)` must stay first in `onCreateBeforeContent` — mail servers need system CAs, not the first-party bundle - `DateMillisBackfill`/`PeekContentBackfill` are one-time migrations gated on `runIfNeeded`; skipping them breaks sort order and snippet previews - IDLE push is foreground-gated via `AppLifecycleTracker` — background delivery goes through the hourly worker + notifications, not the socket - 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 - `network/imap/TrustAll.kt` exists for debug only; never widen its use - 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) - 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 ## Key files ### Root — entry + navigation - com/vayunmathur/email/MainActivity.kt - com/vayunmathur/email/Navigation.kt - com/vayunmathur/email/Route.kt ### data/ — Room stores + sync workers - com/vayunmathur/email/data/EmailModels.kt - com/vayunmathur/email/data/EmailDatabase.kt - com/vayunmathur/email/data/EmailAccountDao.kt - com/vayunmathur/email/data/EmailAccountStore.kt - com/vayunmathur/email/data/EmailMessageDao.kt - com/vayunmathur/email/data/EmailMessageStore.kt - com/vayunmathur/email/data/EmailOutboxDao.kt - com/vayunmathur/email/data/EmailOutboxStore.kt - com/vayunmathur/email/data/EmailQueryDao.kt - com/vayunmathur/email/data/EmailQueryStore.kt - com/vayunmathur/email/data/EmailRepository.kt - com/vayunmathur/email/data/EmailSettings.kt - com/vayunmathur/email/data/EmailSyncState.kt - com/vayunmathur/email/data/EmailSyncWorker.kt - com/vayunmathur/email/data/ImapIdleService.kt - com/vayunmathur/email/data/ImapIdleRetryWorker.kt - com/vayunmathur/email/data/OutboxSendWorker.kt - com/vayunmathur/email/data/SnoozeWorker.kt - com/vayunmathur/email/data/OutlookOAuth.kt - com/vayunmathur/email/data/ProviderPresets.kt - com/vayunmathur/email/data/CredentialCrypto.kt - com/vayunmathur/email/data/EmailBackup.kt — sanitized platform-backup payload (accounts/folders/blocked senders, no secrets) + `needsReauth()` - com/vayunmathur/email/data/DateMillisBackfill.kt - com/vayunmathur/email/data/PeekContentBackfill.kt ### network/ — raw IMAP + SMTP clients - com/vayunmathur/email/network/imap/ImapClient.kt - com/vayunmathur/email/network/imap/RawImapConnection.kt - com/vayunmathur/email/network/imap/ImapWireIo.kt - com/vayunmathur/email/network/imap/ImapParser.kt - com/vayunmathur/email/network/imap/ImapFetchPipeline.kt - com/vayunmathur/email/network/imap/MimeParser.kt - com/vayunmathur/email/network/imap/MimeDecoding.kt — quoted-printable/charset/RFC2047/date/filename/multipart decoding extracted from MimeParser (MimeParser delegates) - com/vayunmathur/email/network/imap/MimeParserParts.kt - com/vayunmathur/email/network/imap/ImapAuthException.kt - com/vayunmathur/email/network/imap/TrustAll.kt — debug only - com/vayunmathur/email/network/smtp/SmtpClient.kt - com/vayunmathur/email/network/smtp/RawSmtpConnection.kt - com/vayunmathur/email/network/smtp/MimeBuilder.kt ### platform/ — ViewModel, actions, notifications, lifecycle - com/vayunmathur/email/platform/EmailViewModel.kt - com/vayunmathur/email/platform/StartupGuard.kt — isolated best-effort startup steps (#939) - 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 - com/vayunmathur/email/platform/EmailManager.kt - com/vayunmathur/email/platform/EmailUiContract.kt - com/vayunmathur/email/platform/EmailClientFlag.kt - com/vayunmathur/email/platform/EmailSendActions.kt - com/vayunmathur/email/platform/EmailDraftActions.kt - com/vayunmathur/email/platform/AiSummaryHelper.kt - com/vayunmathur/email/platform/EmailNotifications.kt - com/vayunmathur/email/platform/EmailNotificationActionReceiver.kt - com/vayunmathur/email/platform/AppLifecycleTracker.kt - com/vayunmathur/email/platform/BootReceiver.kt - com/vayunmathur/email/platform/EmlUtils.kt - com/vayunmathur/email/platform/IntentState.kt ### ui/ — list, thread, composer, account flows - com/vayunmathur/email/ui/MainContent.kt - com/vayunmathur/email/ui/MessageListScreen.kt - com/vayunmathur/email/ui/MessageThreadScreen.kt — thread pane: strip + one open message, no outer scroller - com/vayunmathur/email/ui/ThreadMessageStrip.kt - com/vayunmathur/email/ui/MessageItem.kt — header / self-scrolling body / footer - com/vayunmathur/email/ui/MessageFooter.kt - com/vayunmathur/email/ui/FolderList.kt - com/vayunmathur/email/ui/DetailItem.kt - com/vayunmathur/email/ui/ComposerScreen.kt - com/vayunmathur/email/ui/ComposerHeader.kt - com/vayunmathur/email/ui/ComposerAttachments.kt - com/vayunmathur/email/ui/ComposerHelpers.kt - com/vayunmathur/email/ui/AttachmentItem.kt - com/vayunmathur/email/ui/composer/EmailHtmlEditor.kt - com/vayunmathur/email/ui/composer/EmailHtmlEditorController.kt - com/vayunmathur/email/ui/composer/EmailHtmlSerializer.kt - com/vayunmathur/email/ui/composer/EmailHtmlTagHandler.kt - com/vayunmathur/email/ui/composer/EmailHtmlInline.kt - com/vayunmathur/email/ui/composer/InlineImage.kt - com/vayunmathur/email/ui/composer/CidImageSpan.kt - com/vayunmathur/email/ui/DraftsContent.kt, OutboxContent.kt, SettingsContent.kt, EmlViewerContent.kt — stateless slices for previews - com/vayunmathur/email/ui/EmailDialogEntries.kt — `DialogPage()` entries for `UnsubscribeDialog` + `MessageDetailsDialog` - com/vayunmathur/email/ui/dialogs/UnsubscribeDialogContent.kt — stateless unsubscribe confirmation - com/vayunmathur/email/ui/dialogs/MessageDetailsDialogContent.kt — stateless message-details sheet - com/vayunmathur/email/ui/NavigationEntries.kt - com/vayunmathur/email/ui/OutboxScreen.kt - com/vayunmathur/email/ui/EmlViewerScreen.kt - com/vayunmathur/email/ui/AddAccountScreen.kt - com/vayunmathur/email/ui/AddAccountSection.kt - com/vayunmathur/email/ui/AddAccountInstructionsCard.kt - com/vayunmathur/email/ui/OAuthActivity.kt - com/vayunmathur/email/ui/SettingsScreen.kt - com/vayunmathur/email/ui/EmailUiHelpers.kt ### intents/ — assistant IPC - com/vayunmathur/email/intents/GetRecentIntent.kt - com/vayunmathur/email/intents/SearchIntent.kt - com/vayunmathur/email/intents/EmailDataMapper.kt ### widget/ — unified-inbox home widget - com/vayunmathur/email/widget/EmailWidget.kt — includes `EmailWidgetReceiver` (one widget, one file) ## Verify (this module only) ``` ./gradlew :email:compileDevKotlin ./gradlew :email:lint ./gradlew :email:checkMetadata ```