Repository: thunderbird/thunderbird-android (language: kotlin)

Issue:
Unified inbox doesn't show up
- [ ] ### Checklist

- [x] I have used the search function to see if someone else has already submitted the same bug report.
- [x] I will describe the problem with as much detail as possible.

### App

Thunderbird for Android

### App version

8.2

### Where did you get the app from?

Google Play

### Android version

15

### Device model

OnePlus 11 5G

### Steps to reproduce

1. I uninstalled the Thunderbird app on my phone since it was not getting new emails, while my Gmail and Outlook programs were getting it.
2. So, I re-installed Thunderbird from Google Play Store.
3. I opened Thunderbird after installation and added the first email account from Gmail. I did not see the Unified box, but I thought maybe it's because there's only one email account added. But the gmail account was receiving emails.
4. So I proceeded to add a second email account from Gmail and to my surprise, I still did not see a Unified box.
5. I added a third email account from Outlook and still no Unified box showed up, even though each individual account was getting and showing it's emails from the email server.
6. I then closed the Thunderbird app and re- opened it.
7. To my shock and surprise the Unified box was now showing after some frustrating steps.

In my view, the Unified box should always be there whether there's one email account or more than one. OR you could not show the Unified box if only one account is added, but automatically show it as soon as the second account is added. The first option of always showing Unified box seems more intuitive to me and a better option for your app users.

### Expected behavior

The Unified box should have been there as soon as an email account was added.

### Actual behavior

No Unified box showed up after adding the first email account and after adding the next two accounts.

### Logs

_No response_


Discussion hints:
I just experienced something similar. I installed Thunderbird In my Samsung tablet running android 14. I added 3 mailboxes, no unified inbox. I did a force close, still no unified inbox. I had to force close a total of 5 times before the unified inbox showed up.
This is a bug.
 
Expected behavior: When setting up a second account, the inbox should be enabled automatically. However, adding a third account should preserve existing settings, specifically respecting users who have disabled unified inbox configuration.

Pull request: Fixes Unified inbox doesn't show up
- Fixes #8757
- Added tests to cover `UnifiedInboxConfigurator`'s functionality


Test command: ./gradlew :legacy:core:testDebugUnitTest --tests "com.fsck.k9.UnifiedInboxConfiguratorTest"

Fix patch:
diff --git a/legacy/core/src/main/java/com/fsck/k9/preferences/UnifiedInboxConfigurator.kt b/legacy/core/src/main/java/com/fsck/k9/preferences/UnifiedInboxConfigurator.kt
index ac2a2e65fce..11b308798fd 100644
--- a/legacy/core/src/main/java/com/fsck/k9/preferences/UnifiedInboxConfigurator.kt
+++ b/legacy/core/src/main/java/com/fsck/k9/preferences/UnifiedInboxConfigurator.kt
@@ -10,7 +10,7 @@ class UnifiedInboxConfigurator(
     private val accountManager: AccountManager,
 ) {
     fun configureUnifiedInbox() {
-        if (accountManager.getAccounts().size > 1) {
+        if (accountManager.getAccounts().size == 2) {
             K9.isShowUnifiedInbox = true
             K9.saveSettingsAsync()
         }


Test patch:
diff --git a/legacy/core/src/test/java/com/fsck/k9/UnifiedInboxConfiguratorTest.kt b/legacy/core/src/test/java/com/fsck/k9/UnifiedInboxConfiguratorTest.kt
new file mode 100644
index 00000000000..064bbd13e0f
--- /dev/null
+++ b/legacy/core/src/test/java/com/fsck/k9/UnifiedInboxConfiguratorTest.kt
@@ -0,0 +1,82 @@
+package com.fsck.k9
+
+import app.k9mail.legacy.account.AccountManager
+import com.fsck.k9.preferences.RealGeneralSettingsManager
+import com.fsck.k9.preferences.UnifiedInboxConfigurator
+import org.junit.After
+import org.junit.Assert.assertTrue
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.koin.core.context.GlobalContext.startKoin
+import org.koin.core.context.GlobalContext.stopKoin
+import org.koin.dsl.module
+import org.mockito.Mockito.mock
+import org.mockito.Mockito.`when`
+import org.mockito.junit.MockitoJUnitRunner
+
+@RunWith(MockitoJUnitRunner::class)
+class UnifiedInboxConfiguratorTest {
+
+    private lateinit var accountManager: AccountManager
+    private lateinit var configurator: UnifiedInboxConfigurator
+
+    @Before
+    fun setUp() {
+        accountManager = mock(AccountManager::class.java)
+        configurator = UnifiedInboxConfigurator(accountManager)
+
+        // Start Koin with a minimal module
+        startKoin {
+            modules(
+                module {
+                    single { mock(RealGeneralSettingsManager::class.java) }
+                },
+            )
+        }
+
+        // Reset K9 settings to avoid state leakage across tests
+        K9.isShowUnifiedInbox = false
+    }
+
+    @After
+    fun tearDown() {
+        stopKoin()
+    }
+
+    @Test
+    fun `configureUnifiedInbox should enable unified inbox when there are exactly two accounts`() {
+        // Given
+        `when`(accountManager.getAccounts()).thenReturn(listOf(mock(), mock()))
+
+        // When
+        configurator.configureUnifiedInbox()
+
+        // Then
+        assertTrue(K9.isShowUnifiedInbox)
+    }
+
+    @Test
+    fun `configureUnifiedInbox should not enable unified inbox when there are less than two accounts`() {
+        // Given
+        `when`(accountManager.getAccounts()).thenReturn(listOf(mock()))
+
+        // When
+        configurator.configureUnifiedInbox()
+
+        // Then
+        assertTrue(!K9.isShowUnifiedInbox)
+    }
+
+    @Test
+    fun `configureUnifiedInbox should not enable unified inbox when there are more than two accounts`() {
+        // Given
+        `when`(accountManager.getAccounts()).thenReturn(listOf(mock(), mock(), mock()))
+
+        // When
+        configurator.configureUnifiedInbox()
+
+        // Then
+        assertTrue(!K9.isShowUnifiedInbox)
+    }
+}