Repository: thundernest/k-9
Issue: Asks to save unchanged draft

### 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

6.400

### Where did you get the app from?

F-Droid

### Android version

7.1

### Device model

_No response_

### Steps to reproduce

1. Click the pencil to make a draft.
2. Add a recipient and a body.
3. Press Back and tap `Save as draft`.
4. Open this draft.
5. Do not change anything, just press Back.
6. You are asked to save or discard changes.
7. If you did **not** set a recipient in step 2 (only set a message body), then step 6 has the expected behavior, i.e. you are **not** asked to save or discard changes.

### Expected behavior

The app should notice that the message was unchanged and do not ask to save or discard changes.

### Actual behavior

The app asks to save or discard changes.

### Logs

_No response_

Changed files:
app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.kt, app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientMvpView.kt

diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientMvpView.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientMvpView.kt
index 3177640af..910b606be 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientMvpView.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientMvpView.kt
@@ -192,6 +192,30 @@ class RecipientMvpView(private val activity: MessageCompose) : View.OnFocusChang
         }
     }
 
+    fun silentlyAddRecipients(recipientType: RecipientType, vararg recipients: Recipient) {
+        removeAllTextListenersFromView(recipientType)
+        addRecipients(recipientType, *recipients)
+        addAllTextListenersToView(recipientType)
+    }
+
+    private fun removeAllTextListenersFromView(recipientType: RecipientType) {
+        when (recipientType) {
+            RecipientType.TO -> removeAllTextChangedListeners(toView)
+            RecipientType.CC -> removeAllTextChangedListeners(ccView)
+            RecipientType.BCC -> removeAllTextChangedListeners(bccView)
+            else -> throw AssertionError("Unsupported type: $recipientType")
+        }
+    }
+
+    private fun addAllTextListenersToView(recipientType: RecipientType) {
+        when (recipientType) {
+            RecipientType.TO -> addAllTextChangedListeners(toView)
+            RecipientType.CC -> addAllTextChangedListeners(ccView)
+            RecipientType.BCC -> addAllTextChangedListeners(bccView)
+            else -> throw AssertionError("Unsupported type: $recipientType")
+        }
+    }
+
     fun silentlyAddBccAddresses(vararg recipients: Recipient) {
         removeAllTextChangedListeners(bccView)
 
diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.kt
index b907da7a0..250971225 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/RecipientPresenter.kt
@@ -490,7 +490,7 @@ class RecipientPresenter(
         object : RecipientLoader(context, account.openPgpProvider, *addresses) {
             override fun deliverResult(result: List<Recipient>?) {
                 val recipientArray = result!!.toTypedArray()
-                recipientMvpView.addRecipients(recipientType, *recipientArray)
+                recipientMvpView.silentlyAddRecipients(recipientType, *recipientArray)
 
                 stopLoading()
                 abandon()