Repository: thundernest/k-9
Issue: Crash when confirm delete dialog after rotate

### 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 version

5.915

### Where did you get the app from?

Other

### Android version

8.1.0

### Device model

Android Emulator

### Steps to reproduce

1. Go to settings
2. Go to General Settings
3. Go to Interactions
4. Enable Delete Confirm action
5. Come back to the messages list
6. select a message
7. click on the Delete icon
8. rotate the device
9. Click on Yes

### Expected behavior

Delete should happen successfully


### Actual behavior

Crash!

### Logs

```
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.fsck.k9.debug, PID: 7717
    java.lang.NullPointerException
        at com.fsck.k9.fragment.MessageListFragment.doPositiveClick(MessageListFragment.kt:1163)
        at com.fsck.k9.fragment.ConfirmationDialogFragment.onClick(ConfirmationDialogFragment.java:80)
        at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

```

Changed files:
app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.kt

diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.kt b/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.kt
index 237a6a408..2da9c75eb 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.kt
@@ -159,6 +159,7 @@ class MessageListFragment :
     private fun restoreInstanceState(savedInstanceState: Bundle?) {
         if (savedInstanceState == null) return
 
+        activeMessages = savedInstanceState.getStringArray(STATE_ACTIVE_MESSAGES)?.map { MessageReference.parse(it)!! }
         restoreSelectedMessages(savedInstanceState)
         isRemoteSearch = savedInstanceState.getBoolean(STATE_REMOTE_SEARCH_PERFORMED)
         savedListState = savedInstanceState.getParcelable(STATE_MESSAGE_LIST)
@@ -438,6 +439,10 @@ class MessageListFragment :
         saveListState(outState)
         outState.putLongArray(STATE_SELECTED_MESSAGES, selected.toLongArray())
         outState.putBoolean(STATE_REMOTE_SEARCH_PERFORMED, isRemoteSearch)
+        outState.putStringArray(
+            STATE_ACTIVE_MESSAGES,
+            activeMessages?.map(MessageReference::toIdentityString)?.toTypedArray()
+        )
         if (activeMessage != null) {
             outState.putString(STATE_ACTIVE_MESSAGE, activeMessage!!.toIdentityString())
         }
@@ -1945,6 +1950,7 @@ class MessageListFragment :
         private const val ARG_IS_THREAD_DISPLAY = "isThreadedDisplay"
 
         private const val STATE_SELECTED_MESSAGES = "selectedMessages"
+        private const val STATE_ACTIVE_MESSAGES = "activeMessages"
         private const val STATE_ACTIVE_MESSAGE = "activeMessage"
         private const val STATE_REMOTE_SEARCH_PERFORMED = "remoteSearchPerformed"
         private const val STATE_MESSAGE_LIST = "listState"