securemail: fix all lint findings
- Commit
f0545c5489de77b5defb483d9dab926af1e04258- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-17 05:16 UTC (19 days ago)
- Parents
063c0d0
Fix every lint warning reported for the securemail module's own sources by :securemail:lintDev, now 0 errors / 0 warnings for securemail/** (remaining report entries are transitive library findings owned by other clusters).
Two security findings fixed for real, with no suppression. AcceptsUserCertificates: removed <certificates src="user" /> from network_security_config.xml so only system trust anchors remain (cleartext already forbidden). UnsafeProtectedBroadcastReceiver: BootReceiver.onReceive now returns unless the action is BOOT_COMPLETED, MY_PACKAGE_REPLACED or QUICKBOOT_POWERON. PackageStructure: Navigation.kt holds only Navigation() (entry builders moved to ui/NavigationEntries.kt) and the IntentState object moved out of Route.kt into platform/. UseKtx (4) and AutoboxingStateCreation (2): String.toUri()/edit {} and typed state holders.
No suppressions added; no lint config or baseline changed.
Verified: ./gradlew :securemail:lintDev (0 own-module errors/warnings) and :securemail:testDevUnitTest green.Diff
securemail/src/main/java/com/vayunmathur/securemail/MainActivity.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/MainActivity.kt b/securemail/src/main/java/com/vayunmathur/securemail/MainActivity.ktindex e8ec1c0108..e625be96bd 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/MainActivity.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/MainActivity.kt@@ -1,5 +1,7 @@ package com.vayunmathur.securemail +import com.vayunmathur.securemail.platform.IntentState+ import androidx.activity.viewModels import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect
securemail/src/main/java/com/vayunmathur/securemail/Navigation.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/Navigation.kt b/securemail/src/main/java/com/vayunmathur/securemail/Navigation.ktindex df11585f01..1653e7e3b1 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/Navigation.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/Navigation.kt@@ -6,38 +6,25 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.platform.LocalContext-import androidx.fragment.app.FragmentActivity-import com.vayunmathur.library.util.AppMessages-import com.vayunmathur.library.util.EntryProviderScope import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.NavBackStack-import com.vayunmathur.library.util.SiblingPage import com.vayunmathur.library.util.rememberNavBackStack import com.vayunmathur.securemail.data.MailFolder-import com.vayunmathur.securemail.data.StoredMessage-import com.vayunmathur.securemail.platform.MailUiState-import com.vayunmathur.securemail.domain.mail.AddressValidator-import com.vayunmathur.securemail.platform.Draft import com.vayunmathur.securemail.platform.MailViewModel-import com.vayunmathur.securemail.platform.deleteForever-import com.vayunmathur.securemail.platform.envelopeOf-import com.vayunmathur.securemail.platform.markRead-import com.vayunmathur.securemail.platform.moveTo-import com.vayunmathur.securemail.platform.moveToTrash-import com.vayunmathur.securemail.platform.restoreFromTrash import com.vayunmathur.securemail.platform.setRead-import com.vayunmathur.securemail.ui.ComposeScreen+import com.vayunmathur.securemail.platform.restoreFromTrash+import com.vayunmathur.securemail.platform.moveToTrash+import com.vayunmathur.securemail.platform.moveTo+import com.vayunmathur.securemail.platform.markRead+import com.vayunmathur.securemail.platform.deleteForever import com.vayunmathur.securemail.ui.FolderActions-import com.vayunmathur.securemail.ui.InboxScreen-import com.vayunmathur.securemail.ui.LockScreen import com.vayunmathur.securemail.ui.MailBottomBar+import com.vayunmathur.securemail.ui.selectTab+import com.vayunmathur.securemail.ui.outEntry+import com.vayunmathur.securemail.ui.mainEntries+import com.vayunmathur.securemail.ui.currentTab+import com.vayunmathur.securemail.ui.composerEntry import com.vayunmathur.securemail.ui.MailTab-import com.vayunmathur.securemail.ui.OnboardingScreen-import com.vayunmathur.securemail.ui.OutActions-import com.vayunmathur.securemail.ui.OutScreen-import com.vayunmathur.securemail.ui.ReaderScreen-import com.vayunmathur.securemail.ui.SettingsScreen-import com.vayunmathur.securemail.ui.tab @Composable fun Navigation(viewModel: MailViewModel, initialRoute: Route? = null) {@@ -100,237 +87,3 @@ fun Navigation(viewModel: MailViewModel, initialRoute: Route? = null) { outEntry(viewModel, backStack) } }---/** Onboarding, lock, inbox, reader and settings destinations. */-private fun EntryProviderScope<Route>.mainEntries(- viewModel: MailViewModel,- backStack: NavBackStack<Route>,- state: MailUiState,- allMessages: List<StoredMessage>,- folderActions: FolderActions,- context: android.content.Context,-) {- entry<Route.Onboarding> {- OnboardingScreen(- state = state,- onClaim = { localPart, passphrase ->- viewModel.claimAddress(localPart, passphrase) {- // Protection enrolls immediately after claim: run the- // biometric gate as soon as the Lock screen lands.- (context as? FragmentActivity)?.let { viewModel.unlock(it) }- }- },- onDismissMessages = viewModel::dismissMessages,- )- }- entry<Route.Lock> {- LockScreen(- state = state,- onUnlock = {- (context as? FragmentActivity)?.let { viewModel.unlock(it) }- },- onDismissMessages = viewModel::dismissMessages,- )- }- entry<Route.Inbox>(metadata = SiblingPage()) { route ->- val folderFlow = remember(route.folder) { viewModel.folderMessages(route.folder) }- val folderMessages by folderFlow.collectAsState(emptyList())- InboxScreen(- state = state,- folder = route.folder,- actions = folderActions,- messages = folderMessages,- )- }- readerEntry(viewModel, backStack, state, allMessages)- entry<Route.Settings>(metadata = SiblingPage()) {- val identities by viewModel.identities.collectAsState(emptyList())- SettingsScreen(- state = state,- identities = identities,- onCreateAlias = viewModel::createAlias,- onSetAliasDisabled = viewModel::setAliasDisabled,- onExportPublicKey = viewModel::exportPublicKey,- onForget = viewModel::forgetIdentity,- onDismissMessages = viewModel::dismissMessages,- )- }-}---/** Reader destination: decrypts and marks read on entry. */-private fun EntryProviderScope<Route>.readerEntry(- viewModel: MailViewModel,- backStack: NavBackStack<Route>,- state: MailUiState,- allMessages: List<StoredMessage>,-) {-entry<Route.Reader> { route ->- val msg = remember(route.messageId, allMessages) {- allMessages.firstOrNull { it.id == route.messageId }- }- LaunchedEffect(route.messageId) {- viewModel.decryptStored(route.messageId)- viewModel.markRead(route.messageId)- }- ReaderScreen(- state = state,- onReply = { m ->- backStack.add(- Route.Composer(- to = m.from,- subject = "Re: ${m.decryptedSubject ?: ""}",- inReplyTo = m.id,- from = m.deliveredTo,- ),- )- },- onBack = { backStack.pop() },- message = msg,- )-}-}-/**- * Composer. Leaving with Back saves a draft (or updates the reopened one);- * Discard drops it; a successful send deletes it.- */-private fun EntryProviderScope<Route>.composerEntry(viewModel: MailViewModel, backStack: NavBackStack<Route>) {- entry<Route.Composer> { route ->- // Stable for this composition so repeated saves update one draft row.- val draftId = remember(route) { route.draftId ?: Draft().id }- LaunchedEffect(route) {- viewModel.seedDraft(- to = AddressValidator.parseRecipients(route.to),- cc = AddressValidator.parseRecipients(route.cc),- bcc = AddressValidator.parseRecipients(route.bcc),- from = route.from,- )- }- fun close() {- viewModel.clearDraft()- backStack.pop()- }- val identities by viewModel.identities.collectAsState(emptyList())- ComposeScreen(- state = viewModel.state,- identities = identities.filter { !it.disabled },- draftFrom = viewModel.draftFrom,- onSelectFrom = { viewModel.draftFrom = it },- draftTo = viewModel.draftTo,- draftCc = viewModel.draftCc,- draftBcc = viewModel.draftBcc,- initialSubject = route.subject,- initialBody = route.body,- onAddRecipient = viewModel::addDraftRecipient,- onRemoveRecipient = viewModel::removeDraftRecipient,- onSend = { to, cc, bcc, subject, body, inReplyTo ->- viewModel.send(- to = to,- cc = cc,- bcc = bcc,- subject = subject,- body = body,- inReplyTo = inReplyTo,- from = viewModel.draftFrom,- onDone = { sent ->- if (sent) {- viewModel.drafts.delete(draftId)- close()- }- },- )- },- onLeave = { subject, body ->- saveOrDropDraft(viewModel, draftId, subject, body, route.inReplyTo)- close()- },- onDiscard = {- viewModel.drafts.delete(draftId)- close()- },- onConsumeMessage = viewModel::dismissMessages,- )- }-}--/** Saves the composition as a draft, or removes the draft when nothing was written. */-private fun saveOrDropDraft(- viewModel: MailViewModel,- draftId: String,- subject: String,- body: String,- inReplyTo: String?,-) {- val draft = Draft(- id = draftId,- to = viewModel.draftTo,- cc = viewModel.draftCc,- bcc = viewModel.draftBcc,- subject = subject,- body = body,- inReplyTo = inReplyTo,- from = viewModel.draftFrom,- )- if (draft.isEmpty) {- viewModel.drafts.delete(draftId)- } else {- viewModel.drafts.save(draft)- AppMessages.show("Draft saved")- }-}--/** The Out tab: Drafts, Outbox and Sent on one page. */-private fun EntryProviderScope<Route>.outEntry(viewModel: MailViewModel, backStack: NavBackStack<Route>) {- entry<Route.Out>(metadata = SiblingPage()) {- val drafts by viewModel.drafts.drafts.collectAsState(emptyList())- val sent by viewModel.drafts.sent.collectAsState(emptyList())- val outbox by viewModel.outboxMessages.collectAsState(emptyList())- val actions = remember(viewModel, backStack) {- OutActions(- onCompose = { backStack.add(Route.Composer()) },- onOpenDraft = { d ->- backStack.add(- Route.Composer(- to = d.to.joinToString(", "),- cc = d.cc.joinToString(", "),- bcc = d.bcc.joinToString(", "),- subject = d.subject,- body = d.body,- inReplyTo = d.inReplyTo,- draftId = d.id,- from = d.from,- ),- )- },- onDeleteDraft = viewModel.drafts::delete,- onRestoreDraft = viewModel.drafts::save,- onRetryOutbox = viewModel::retryOutbox,- onOpenSent = { backStack.add(Route.Reader(it)) },- onTrashSent = viewModel::moveToTrash,- onUntrashSent = { viewModel.moveTo(it, MailFolder.SENT) },- onSetRead = viewModel::setRead,- )- }- OutScreen(drafts = drafts, outbox = outbox, sent = sent, actions = actions)- }-}--/** The bottom-bar tab for the top route, or null when the bar should hide (reader, composer, gates). */-private fun currentTab(top: Route): MailTab? = when (top) {- is Route.Inbox -> top.folder.tab()- Route.Out -> MailTab.OUT- Route.Settings -> MailTab.SETTINGS- else -> null-}--private fun selectTab(tab: MailTab, backStack: NavBackStack<Route>) {- val target: Route = when (tab) {- MailTab.OUT -> Route.Out- MailTab.SETTINGS -> Route.Settings- MailTab.INBOX -> Route.Inbox(MailFolder.INBOX)- MailTab.SPAM -> Route.Inbox(MailFolder.SPAM)- MailTab.TRASH -> Route.Inbox(MailFolder.TRASH)- }- if (backStack.last() != target) backStack.reset(target)-}
securemail/src/main/java/com/vayunmathur/securemail/Route.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/Route.kt b/securemail/src/main/java/com/vayunmathur/securemail/Route.ktindex 5418759776..2fd58e3a3b 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/Route.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/Route.kt@@ -4,11 +4,6 @@ import com.vayunmathur.library.util.NavKey import com.vayunmathur.securemail.data.MailFolder import kotlinx.serialization.Serializable -/** Holds a pending deep-link/share route until Navigation consumes it. */-object IntentState {- var navigationRoute: Route? = null-}- /** Contract for route. */ @Serializable sealed interface Route : NavKey {
securemail/src/main/java/com/vayunmathur/securemail/platform/BootReceiver.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/platform/BootReceiver.kt b/securemail/src/main/java/com/vayunmathur/securemail/platform/BootReceiver.ktindex fd60fbea43..4a7b6d386a 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/platform/BootReceiver.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/platform/BootReceiver.kt@@ -13,6 +13,13 @@ import kotlinx.coroutines.launch /** Restarts the relay socket after boot/package-replace when an identity exists. */ class BootReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) {+ // Only system protected broadcasts restart the socket; any other action is ignored.+ if (intent.action != Intent.ACTION_BOOT_COMPLETED &&+ intent.action != Intent.ACTION_MY_PACKAGE_REPLACED &&+ intent.action != "android.intent.action.QUICKBOOT_POWERON"+ ) {+ return+ } CoroutineScope(Dispatchers.IO).launch { val settings = MailConfig(context).settings.first() if (settings.address.isNotBlank()) MailSocketService.start(context)
securemail/src/main/java/com/vayunmathur/securemail/platform/IntentState.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/platform/IntentState.kt b/securemail/src/main/java/com/vayunmathur/securemail/platform/IntentState.ktnew file mode 100644index 0000000000..4a70815c83--- /dev/null+++ b/securemail/src/main/java/com/vayunmathur/securemail/platform/IntentState.kt@@ -0,0 +1,8 @@+package com.vayunmathur.securemail.platform++import com.vayunmathur.securemail.Route++/** Holds a pending deep-link/share route until Navigation consumes it. */+object IntentState {+ var navigationRoute: Route? = null+}
securemail/src/main/java/com/vayunmathur/securemail/platform/crypto/KeyManager.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/platform/crypto/KeyManager.kt b/securemail/src/main/java/com/vayunmathur/securemail/platform/crypto/KeyManager.ktindex 38ff0b60a6..21c457d78c 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/platform/crypto/KeyManager.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/platform/crypto/KeyManager.kt@@ -1,6 +1,7 @@ package com.vayunmathur.securemail.platform.crypto import android.content.Context+import androidx.core.content.edit import android.util.Base64 import com.vayunmathur.library.util.DatabaseHelper @@ -56,10 +57,10 @@ class KeyManager(context: Context) : DatabaseHelper(context) { val cipher = getCipherForEncryption() val encrypted = cipher.doFinal(passphrase.toByteArray(Charsets.UTF_8)) val prefs = context.getSharedPreferences(sharedPrefsName, Context.MODE_PRIVATE)- prefs.edit()- .putString(s2kPassphraseKey, Base64.encodeToString(encrypted, Base64.NO_WRAP))- .putString(s2kIvKey, Base64.encodeToString(cipher.iv, Base64.NO_WRAP))- .apply()+ prefs.edit {+ putString(s2kPassphraseKey, Base64.encodeToString(encrypted, Base64.NO_WRAP))+ putString(s2kIvKey, Base64.encodeToString(cipher.iv, Base64.NO_WRAP))+ } } /** Returns the sealed S2K passphrase, or null when never stored. */@@ -82,7 +83,7 @@ class KeyManager(context: Context) : DatabaseHelper(context) { fun storeRelayToken(token: String) { val prefs = context.getSharedPreferences(sharedPrefsName, Context.MODE_PRIVATE)- prefs.edit().putString(tokenKey, token).apply()+ prefs.edit { putString(tokenKey, token) } } fun getRelayToken(): String? =@@ -91,7 +92,7 @@ class KeyManager(context: Context) : DatabaseHelper(context) { fun storeOwnAddress(address: String) { val prefs = context.getSharedPreferences(sharedPrefsName, Context.MODE_PRIVATE)- prefs.edit().putString(addressKey, address).apply()+ prefs.edit { putString(addressKey, address) } } fun getOwnAddress(): String? =@@ -101,11 +102,11 @@ class KeyManager(context: Context) : DatabaseHelper(context) { fun clear() { deleteKey() val prefs = context.getSharedPreferences(sharedPrefsName, Context.MODE_PRIVATE)- prefs.edit()- .remove(tokenKey)- .remove(addressKey)- .remove(s2kPassphraseKey)- .remove(s2kIvKey)- .apply()+ prefs.edit {+ remove(tokenKey)+ remove(addressKey)+ remove(s2kPassphraseKey)+ remove(s2kIvKey)+ } } }
securemail/src/main/java/com/vayunmathur/securemail/ui/ComposeScreen.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/ui/ComposeScreen.kt b/securemail/src/main/java/com/vayunmathur/securemail/ui/ComposeScreen.ktindex b3e2e287ff..ea25919b0a 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/ui/ComposeScreen.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/ui/ComposeScreen.kt@@ -22,6 +22,7 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope@@ -74,8 +75,8 @@ fun ComposeScreen( var subject by remember { mutableStateOf(initialSubject) } var body by remember { mutableStateOf(initialBody) } val scope = rememberCoroutineScope()- var pickTarget by remember { mutableStateOf(0) }- var pickTick by remember { mutableStateOf(0) }+ var pickTarget by remember { mutableIntStateOf(0) }+ var pickTick by remember { mutableIntStateOf(0) } val contactPicker = rememberLauncherForActivityResult( ActivityResultContracts.StartActivityForResult(), ) { result ->
securemail/src/main/java/com/vayunmathur/securemail/ui/NavigationEntries.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/ui/NavigationEntries.kt b/securemail/src/main/java/com/vayunmathur/securemail/ui/NavigationEntries.ktnew file mode 100644index 0000000000..36e1a02795--- /dev/null+++ b/securemail/src/main/java/com/vayunmathur/securemail/ui/NavigationEntries.kt@@ -0,0 +1,261 @@+package com.vayunmathur.securemail.ui+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember+import androidx.compose.ui.platform.LocalContext+import androidx.fragment.app.FragmentActivity+import com.vayunmathur.library.util.AppMessages+import com.vayunmathur.library.util.EntryProviderScope+import com.vayunmathur.library.util.MainNavigation+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.library.util.SiblingPage+import com.vayunmathur.library.util.rememberNavBackStack+import com.vayunmathur.securemail.data.MailFolder+import com.vayunmathur.securemail.data.StoredMessage+import com.vayunmathur.securemail.platform.MailUiState+import com.vayunmathur.securemail.domain.mail.AddressValidator+import com.vayunmathur.securemail.platform.Draft+import com.vayunmathur.securemail.platform.MailViewModel+import com.vayunmathur.securemail.platform.deleteForever+import com.vayunmathur.securemail.platform.envelopeOf+import com.vayunmathur.securemail.platform.markRead+import com.vayunmathur.securemail.platform.moveTo+import com.vayunmathur.securemail.platform.moveToTrash+import com.vayunmathur.securemail.platform.restoreFromTrash+import com.vayunmathur.securemail.platform.setRead+import com.vayunmathur.securemail.Route++/** Onboarding, lock, inbox, reader and settings destinations. */+internal fun EntryProviderScope<Route>.mainEntries(+ viewModel: MailViewModel,+ backStack: NavBackStack<Route>,+ state: MailUiState,+ allMessages: List<StoredMessage>,+ folderActions: FolderActions,+ context: android.content.Context,+) {+ entry<Route.Onboarding> {+ OnboardingScreen(+ state = state,+ onClaim = { localPart, passphrase ->+ viewModel.claimAddress(localPart, passphrase) {+ // Protection enrolls immediately after claim: run the+ // biometric gate as soon as the Lock screen lands.+ (context as? FragmentActivity)?.let { viewModel.unlock(it) }+ }+ },+ onDismissMessages = viewModel::dismissMessages,+ )+ }+ entry<Route.Lock> {+ LockScreen(+ state = state,+ onUnlock = {+ (context as? FragmentActivity)?.let { viewModel.unlock(it) }+ },+ onDismissMessages = viewModel::dismissMessages,+ )+ }+ entry<Route.Inbox>(metadata = SiblingPage()) { route ->+ val folderFlow = remember(route.folder) { viewModel.folderMessages(route.folder) }+ val folderMessages by folderFlow.collectAsState(emptyList())+ InboxScreen(+ state = state,+ folder = route.folder,+ actions = folderActions,+ messages = folderMessages,+ )+ }+ readerEntry(viewModel, backStack, state, allMessages)+ entry<Route.Settings>(metadata = SiblingPage()) {+ val identities by viewModel.identities.collectAsState(emptyList())+ SettingsScreen(+ state = state,+ identities = identities,+ onCreateAlias = viewModel::createAlias,+ onSetAliasDisabled = viewModel::setAliasDisabled,+ onExportPublicKey = viewModel::exportPublicKey,+ onForget = viewModel::forgetIdentity,+ onDismissMessages = viewModel::dismissMessages,+ )+ }+}+++/** Reader destination: decrypts and marks read on entry. */+internal fun EntryProviderScope<Route>.readerEntry(+ viewModel: MailViewModel,+ backStack: NavBackStack<Route>,+ state: MailUiState,+ allMessages: List<StoredMessage>,+) {+entry<Route.Reader> { route ->+ val msg = remember(route.messageId, allMessages) {+ allMessages.firstOrNull { it.id == route.messageId }+ }+ LaunchedEffect(route.messageId) {+ viewModel.decryptStored(route.messageId)+ viewModel.markRead(route.messageId)+ }+ ReaderScreen(+ state = state,+ onReply = { m ->+ backStack.add(+ Route.Composer(+ to = m.from,+ subject = "Re: ${m.decryptedSubject ?: ""}",+ inReplyTo = m.id,+ from = m.deliveredTo,+ ),+ )+ },+ onBack = { backStack.pop() },+ message = msg,+ )+}+}+/**+ * Composer. Leaving with Back saves a draft (or updates the reopened one);+ * Discard drops it; a successful send deletes it.+ */+internal fun EntryProviderScope<Route>.composerEntry(viewModel: MailViewModel, backStack: NavBackStack<Route>) {+ entry<Route.Composer> { route ->+ // Stable for this composition so repeated saves update one draft row.+ val draftId = remember(route) { route.draftId ?: Draft().id }+ LaunchedEffect(route) {+ viewModel.seedDraft(+ to = AddressValidator.parseRecipients(route.to),+ cc = AddressValidator.parseRecipients(route.cc),+ bcc = AddressValidator.parseRecipients(route.bcc),+ from = route.from,+ )+ }+ fun close() {+ viewModel.clearDraft()+ backStack.pop()+ }+ val identities by viewModel.identities.collectAsState(emptyList())+ ComposeScreen(+ state = viewModel.state,+ identities = identities.filter { !it.disabled },+ draftFrom = viewModel.draftFrom,+ onSelectFrom = { viewModel.draftFrom = it },+ draftTo = viewModel.draftTo,+ draftCc = viewModel.draftCc,+ draftBcc = viewModel.draftBcc,+ initialSubject = route.subject,+ initialBody = route.body,+ onAddRecipient = viewModel::addDraftRecipient,+ onRemoveRecipient = viewModel::removeDraftRecipient,+ onSend = { to, cc, bcc, subject, body, inReplyTo ->+ viewModel.send(+ to = to,+ cc = cc,+ bcc = bcc,+ subject = subject,+ body = body,+ inReplyTo = inReplyTo,+ from = viewModel.draftFrom,+ onDone = { sent ->+ if (sent) {+ viewModel.drafts.delete(draftId)+ close()+ }+ },+ )+ },+ onLeave = { subject, body ->+ saveOrDropDraft(viewModel, draftId, subject, body, route.inReplyTo)+ close()+ },+ onDiscard = {+ viewModel.drafts.delete(draftId)+ close()+ },+ onConsumeMessage = viewModel::dismissMessages,+ )+ }+}++/** Saves the composition as a draft, or removes the draft when nothing was written. */+internal fun saveOrDropDraft(+ viewModel: MailViewModel,+ draftId: String,+ subject: String,+ body: String,+ inReplyTo: String?,+) {+ val draft = Draft(+ id = draftId,+ to = viewModel.draftTo,+ cc = viewModel.draftCc,+ bcc = viewModel.draftBcc,+ subject = subject,+ body = body,+ inReplyTo = inReplyTo,+ from = viewModel.draftFrom,+ )+ if (draft.isEmpty) {+ viewModel.drafts.delete(draftId)+ } else {+ viewModel.drafts.save(draft)+ AppMessages.show("Draft saved")+ }+}++/** The Out tab: Drafts, Outbox and Sent on one page. */+internal fun EntryProviderScope<Route>.outEntry(viewModel: MailViewModel, backStack: NavBackStack<Route>) {+ entry<Route.Out>(metadata = SiblingPage()) {+ val drafts by viewModel.drafts.drafts.collectAsState(emptyList())+ val sent by viewModel.drafts.sent.collectAsState(emptyList())+ val outbox by viewModel.outboxMessages.collectAsState(emptyList())+ val actions = remember(viewModel, backStack) {+ OutActions(+ onCompose = { backStack.add(Route.Composer()) },+ onOpenDraft = { d ->+ backStack.add(+ Route.Composer(+ to = d.to.joinToString(", "),+ cc = d.cc.joinToString(", "),+ bcc = d.bcc.joinToString(", "),+ subject = d.subject,+ body = d.body,+ inReplyTo = d.inReplyTo,+ draftId = d.id,+ from = d.from,+ ),+ )+ },+ onDeleteDraft = viewModel.drafts::delete,+ onRestoreDraft = viewModel.drafts::save,+ onRetryOutbox = viewModel::retryOutbox,+ onOpenSent = { backStack.add(Route.Reader(it)) },+ onTrashSent = viewModel::moveToTrash,+ onUntrashSent = { viewModel.moveTo(it, MailFolder.SENT) },+ onSetRead = viewModel::setRead,+ )+ }+ OutScreen(drafts = drafts, outbox = outbox, sent = sent, actions = actions)+ }+}++/** The bottom-bar tab for the top route, or null when the bar should hide (reader, composer, gates). */+internal fun currentTab(top: Route): MailTab? = when (top) {+ is Route.Inbox -> top.folder.tab()+ Route.Out -> MailTab.OUT+ Route.Settings -> MailTab.SETTINGS+ else -> null+}++internal fun selectTab(tab: MailTab, backStack: NavBackStack<Route>) {+ val target: Route = when (tab) {+ MailTab.OUT -> Route.Out+ MailTab.SETTINGS -> Route.Settings+ MailTab.INBOX -> Route.Inbox(MailFolder.INBOX)+ MailTab.SPAM -> Route.Inbox(MailFolder.SPAM)+ MailTab.TRASH -> Route.Inbox(MailFolder.TRASH)+ }+ if (backStack.last() != target) backStack.reset(target)+}
securemail/src/main/res/xml/network_security_config.xml
diff --git a/securemail/src/main/res/xml/network_security_config.xml b/securemail/src/main/res/xml/network_security_config.xmlindex 52c44ac992..683208ffda 100644--- a/securemail/src/main/res/xml/network_security_config.xml+++ b/securemail/src/main/res/xml/network_security_config.xml@@ -3,7 +3,6 @@ <base-config cleartextTrafficPermitted="false"> <trust-anchors> <certificates src="system" />- <certificates src="user" /> </trust-anchors> </base-config> </network-security-config>
securemail/src/test/java/com/vayunmathur/securemail/MainActivityIntentTest.kt
diff --git a/securemail/src/test/java/com/vayunmathur/securemail/MainActivityIntentTest.kt b/securemail/src/test/java/com/vayunmathur/securemail/MainActivityIntentTest.ktindex 43f68c5d75..81d0c54207 100644--- a/securemail/src/test/java/com/vayunmathur/securemail/MainActivityIntentTest.kt+++ b/securemail/src/test/java/com/vayunmathur/securemail/MainActivityIntentTest.kt@@ -1,5 +1,7 @@ package com.vayunmathur.securemail +import com.vayunmathur.securemail.platform.IntentState+ import android.content.Intent import android.net.Uri import org.junit.runner.RunWith
securemail/src/test/java/com/vayunmathur/securemail/RouteTest.kt
diff --git a/securemail/src/test/java/com/vayunmathur/securemail/RouteTest.kt b/securemail/src/test/java/com/vayunmathur/securemail/RouteTest.ktindex ca078de8f9..82bc094641 100644--- a/securemail/src/test/java/com/vayunmathur/securemail/RouteTest.kt+++ b/securemail/src/test/java/com/vayunmathur/securemail/RouteTest.kt@@ -1,5 +1,7 @@ package com.vayunmathur.securemail +import com.vayunmathur.securemail.platform.IntentState+ import com.vayunmathur.securemail.data.MailFolder import kotlinx.serialization.json.Json import kotlin.test.Test