Repository: thundernest/k-9
Issue: Unified folders crash K9

### Expected behavior
Opening the "Spam" / any folder in the unified account shows the (spam) folder merged for all accounts in one place.

### Actual behavior
Clicking on "Spam" or any other folder crashes the app, when the unified account is selected.

### Steps to reproduce
1. Switch to the unified account
2. Open the drawer
3. Click on "Spam" or any other folder

### Environment
K-9 Mail version:
5.700

Android version:
Android 9

```
11-28 09:45:08.420 10717 10717 D AndroidRuntime: Shutting down VM
11-28 09:45:08.421 10717 10717 E AndroidRuntime: FATAL EXCEPTION: main
11-28 09:45:08.421 10717 10717 E AndroidRuntime: Process: com.fsck.k9, PID: 10717
11-28 09:45:08.421 10717 10717 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.fsck.k9.Account.getUuid()' on a null object reference
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at com.fsck.k9.activity.MessageList.openFolder(MessageList.java:632)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at com.fsck.k9.ui.K9Drawer$createItemClickListener$1.onItemClick(K9Drawer.kt:204)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at com.mikepenz.materialdrawer.DrawerBuilder$6.onClick(DrawerBuilder.java:1786)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at com.mikepenz.materialdrawer.DrawerBuilder$6.onClick(DrawerBuilder.java:1760)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at com.mikepenz.fastadapter.FastAdapter$1.onClick(FastAdapter.java:609)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at com.mikepenz.fastadapter.utils.EventHookUtil$1.onClick(EventHookUtil.java:72)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at android.view.View.performClick(View.java:6597)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at android.view.View.performClickInternal(View.java:6574)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at android.view.View.access$3100(View.java:778)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at android.view.View$PerformClick.run(View.java:25906)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:873)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:193)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:6718)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
11-28 09:45:08.421 10717 10717 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
11-28 09:45:08.130   908   908 I NotificationService: Cannot find enqueued record for key: 0|com.fsck.k9|35|null|10194
11-28 09:45:08.428   908  2195 W ActivityManager:   Force finishing activity com.fsck.k9/.activity.MessageList
11-28 09:45:08.435 10717 10717 I Process : Sending signal. PID: 10717 SIG: 9
```

Edit: I have now discovered that this issue is not restricted to the spam folder and I have changed the text and headline accordingly.
It is also very inconsistent if the unified folders are shown in the drawer or not.

Changed files:
app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.kt

diff --git a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.kt b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.kt
index ecd7c41b2..eba902d2f 100644
--- a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.kt
+++ b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.kt
@@ -193,7 +193,7 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
             val viewModelProvider = ViewModelProviders.of(parent, MessageListViewModelFactory())
             val viewModel = viewModelProvider.get(MessageListViewModel::class.java)
 
-            foldersLiveData?.removeObserver(foldersObserver)
+            removeFoldersObserver()
             foldersLiveData = viewModel.getFolders(account).apply {
                 observe(parent, foldersObserver)
             }
@@ -202,6 +202,11 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
         }
     }
 
+    private fun removeFoldersObserver() {
+        foldersLiveData?.removeObserver(foldersObserver)
+        foldersLiveData = null
+    }
+
     private fun updateFolderSettingsItem() {
         val drawerItem = drawer.getDrawerItem(DRAWER_ID_FOLDERS)!!
         drawerItem.isEnabled = !unifiedInboxSelected
@@ -297,6 +302,7 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
         selectedColor = 0
         accountHeader.setActiveProfile(DRAWER_ID_UNIFIED_INBOX)
         accountHeader.headerBackgroundView.setColorFilter(0xFFFFFFFFL.toInt(), PorterDuff.Mode.MULTIPLY)
+        removeFoldersObserver()
         clearUserFolders()
         updateFolderSettingsItem()
     }