anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: thundernest/k-9
Issue: [regression] "mark as read" deselects messages

### 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.200

### Where did you get the app from?

F-Droid

### Android version

Android 12/LineageOS 19.1 

### Device model

Motorola G7 (river)

### Steps to reproduce

1. Go to an INBOX
2. Select one or more unread messages
3. Mark them as read (the open envelope icon)

### Expected behavior

Messages are marked as read but are still selected.

### Actual behavior

Messages are marked as read and deselected.

This behavior was apparently introduced in 6.200 and it breaks my workflow to mark messages as read before sending them to spam (see #5767).

### Logs

_No response_

Changed files:
app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt

diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
index 56b054b5a..8635e07bd 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
@@ -595,8 +595,7 @@ open class MessageList :
         return object : DrawerListener {
             override fun onDrawerClosed(drawerView: View) {
                 if (openFolderTransaction != null) {
-                    openFolderTransaction!!.commit()
-                    openFolderTransaction = null
+                    commitOpenFolderTransaction()
                 }
             }
 
@@ -619,14 +618,20 @@ open class MessageList :
         search.addAllowedFolder(folderId)
 
         performSearch(search)
-
-        onMessageListDisplayed()
     }
 
     private fun openFolderImmediately(folderId: Long) {
         openFolder(folderId)
+        commitOpenFolderTransaction()
+    }
+
+    private fun commitOpenFolderTransaction() {
         openFolderTransaction!!.commit()
         openFolderTransaction = null
+
+        messageListFragment!!.onListVisible()
+
+        onMessageListDisplayed()
     }
 
     fun openUnifiedInbox() {
Repository: thundernest/k-9
Issue: K-9 (5.804 from F-Droid) unable to send email

**Describe the bug**
K-9 mail was working to send emails.  Then F-Droid upgraded to 5.804.  Whereupon K-9 mail could no longer send emails and now posts an alert stating: "Authentication failed" / "Authentication failed for ____. Update your server settings".

**To Reproduce**
Steps to reproduce the behavior:
1. Go to Outbox (with an email waiting to send in the outbox)
2. Click on "Send messages"
3. See error appear.

**Expected behavior**
The email is sent.

**Environment (please complete the following information):**
 - K-9 Mail version: 5.804 - latest F-Droid version
 - Android version: 7.1.1
 - Device: Moto E4
 - Account type: SMTP to local Postfix server, unauthenticated, on port 25
 - Outgoing server is set to my local network mail server DNS name (the IP is a 10.0.0.x local network IP) with security set to "none" port set to 25 and "require sign-in" unchecked.

**Logs**
The only debug log item that relates to "sending" a pending email are the following two lines:

08-23 22:26:33.428 23532 23552 I MessagingController: Running command 'sendPendingMessages', seq = 417 (background priority)
08-23 22:26:33.447 23532 23552 I MessagingController:  Command 'sendPendingMessages' completed

However, I did capture the SMTP session between K-9 and my computer that is running my Postfix server, it is below:

> Server data                                           
< K-9 data

>220 ___._____.___ ESMTP Postfix
<EHLO [127.0.0.1]
>250-d820.dp100.com
>250-PIPELINING
>250-SIZE 40960000
>250-VRFY
>250-ETRN
>250-ENHANCEDSTATUSCODES
>250-8BITMIME
>250-DSN
>250 SMTPUTF8
<QUIT

**Additional context**
Downgrading to K-9 5.803 via F-Droid results in emails being sent via the same server where 5.804 simply sends a QUIT, with no change other than to downgrade K-9.

Changed files:
mail/common/src/main/java/com/fsck/k9/mail/ServerSettings.kt

diff --git a/mail/common/src/main/java/com/fsck/k9/mail/ServerSettings.kt b/mail/common/src/main/java/com/fsck/k9/mail/ServerSettings.kt
index d51ad9045..6107331e6 100644
--- a/mail/common/src/main/java/com/fsck/k9/mail/ServerSettings.kt
+++ b/mail/common/src/main/java/com/fsck/k9/mail/ServerSettings.kt
@@ -18,7 +18,7 @@ data class ServerSettings @JvmOverloads constructor(
 ) {
     val isMissingCredentials: Boolean = when (authenticationType) {
         AuthType.EXTERNAL -> clientCertificateAlias == null
-        else -> password == null
+        else -> username.isNotBlank() && password == null
     }
 
     init {
Repository: thundernest/k-9
Issue: No more notification sounds since 5.9(ish)?

I'm currently using 5.901, though I'm not sure if the issue started in 5.900. I noticed that whenever email comes in, I get the notification popup, but no longer any sound. There was one time where it played part of the sound once, but that was it. 

The phone is a Galaxy S8 running Android 9. 

This used to work prior to this version. Thanks.

Changed files:
app/core/src/main/java/com/fsck/k9/notification/SingleMessageNotifications.kt

diff --git a/app/core/src/main/java/com/fsck/k9/notification/SingleMessageNotifications.kt b/app/core/src/main/java/com/fsck/k9/notification/SingleMessageNotifications.kt
index 1ab2cd952..27177b6d4 100644
--- a/app/core/src/main/java/com/fsck/k9/notification/SingleMessageNotifications.kt
+++ b/app/core/src/main/java/com/fsck/k9/notification/SingleMessageNotifications.kt
@@ -13,7 +13,9 @@ internal open class SingleMessageNotifications(
 
     fun buildSingleMessageNotification(account: Account, holder: NotificationHolder): Notification {
         val notificationId = holder.notificationId
-        return createSingleMessageNotificationBuilder(account, holder, notificationId).build()
+        return createSingleMessageNotificationBuilder(account, holder, notificationId)
+            .setNotificationSilent()
+            .build()
     }
 
     fun createSingleMessageNotificationBuilder(
@@ -23,7 +25,6 @@ internal open class SingleMessageNotifications(
     ): NotificationCompat.Builder {
         val content = holder.content
         val builder = createBigTextStyleNotification(account, holder, notificationId)
-        builder.setNotificationSilent()
 
         val deletePendingIntent = actionCreator.createDismissMessagePendingIntent(
             context, content.messageReference, holder.notificationId
Repository: thundernest/k-9
Issue: Message view/Composer follow Oreo+ "System theme" instead of K-9 App theme

### Expected behavior
When "Use app theme" is selected for either Message view or Composer theme, it should apply a theme according to the selection of "Theme". 

### Actual behavior
On my device, K-9 Mail uses the Android 8+ " System theme" if "Use app theme" is selected for either Message view or Composer theme.

### Steps to reproduce
1. Set preferences according to "Theme=Light", "Message view theme=Use app theme"
2. Open a message -> Light themed
3. Go to System settings > Display > Style > [Switch to dark theme] ( Steps apply on LineageOS )
4. Reopen the message -> Dark themed

### Environment
K-9 Mail version: 5.705 (27005) from F-Droid

Android version: LineageOS 15.1 based on AOSP 8.1

Account type (IMAP, POP3, WebDAV/Exchange): IMAP

Please take some time to [retrieve logs](https://github.com/k9mail/k-9/wiki/LoggingErrors) and attach them here:


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

diff --git a/app/ui/src/main/java/com/fsck/k9/ui/ThemeManager.kt b/app/ui/src/main/java/com/fsck/k9/ui/ThemeManager.kt
index 5b3c67cb0..e6962b57c 100644
--- a/app/ui/src/main/java/com/fsck/k9/ui/ThemeManager.kt
+++ b/app/ui/src/main/java/com/fsck/k9/ui/ThemeManager.kt
@@ -14,7 +14,7 @@ class ThemeManager(private val context: Context) {
         get() = when (K9.appTheme) {
             AppTheme.LIGHT -> Theme.LIGHT
             AppTheme.DARK -> Theme.DARK
-            AppTheme.FOLLOW_SYSTEM -> getSystemTheme()
+            AppTheme.FOLLOW_SYSTEM -> if (Build.VERSION.SDK_INT < 28) Theme.LIGHT else getSystemTheme()
         }
 
     val messageViewTheme: Theme
Repository: thundernest/k-9
Issue: Server certificate exception not persisted

### Expected behavior
Once a certificate exception is accepted, it should remain accepted. 

### Actual behavior
Every server fetch requires re-accepting the certificate as an exception. 

### Steps to reproduce
1. Fetch mail from server using invalid TLS certificate. 
2. Accept the server certificate as an exception. 
3. Fetch mail again. 

### Environment
K-9 Mail version:5.202

Android version:6.0.1

Account type (IMAP, POP3, WebDAV/Exchange):
POP

Changed files:
mail/common/src/main/java/com/fsck/k9/mail/ssl/LocalKeyStore.kt

diff --git a/mail/common/src/main/java/com/fsck/k9/mail/ssl/LocalKeyStore.kt b/mail/common/src/main/java/com/fsck/k9/mail/ssl/LocalKeyStore.kt
index 712fc09d5..280a0d602 100644
--- a/mail/common/src/main/java/com/fsck/k9/mail/ssl/LocalKeyStore.kt
+++ b/mail/common/src/main/java/com/fsck/k9/mail/ssl/LocalKeyStore.kt
@@ -112,8 +112,24 @@ class LocalKeyStore(private val directoryProvider: KeyStoreDirectoryProvider) {
 
         return try {
             val storedCert = keyStore.getCertificate(getCertKey(host, port))
-            storedCert == certificate
+            if (storedCert == null) {
+                Timber.v("Couldn't find a stored certificate for %s:%d", host, port)
+                false
+            } else if (storedCert != certificate) {
+                Timber.v(
+                    "Stored certificate for %s:%d doesn't match.\\nExpected:\\n%s\\nActual:\\n%s",
+                    host,
+                    port,
+                    storedCert,
+                    certificate
+                )
+                false
+            } else {
+                Timber.v("Stored certificate for %s:%d matches the server certificate", host, port)
+                true
+            }
         } catch (e: KeyStoreException) {
+            Timber.w(e, "Error reading from KeyStore")
             false
         }
     }
Repository: thundernest/k-9
Issue: BCC header isn't fetched when partial message is downloaded

### 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.505

### Where did you get the app from?

None

### Android version

doesn't matter

### Device model

_No response_

### Steps to reproduce

1. Sync a folder containing a message that is larger than the value in "fetch messages up to" and contains a BCC header
2. Open message details of that message

### Expected behavior

BCC recipients are displayed

### Actual behavior

BCC recipients are not displayed (because the BCC header wasn't downloaded)

### Logs

_No response_

Changed files:
mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt
mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt

diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt
index a74271c2e..472c054a1 100644
--- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt
+++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt
@@ -537,7 +537,7 @@ internal class RealImapFolder(
             fetchFields.add("INTERNALDATE")
             fetchFields.add("RFC822.SIZE")
             fetchFields.add(
-                "BODY.PEEK[HEADER.FIELDS (date subject from content-type to cc " +
+                "BODY.PEEK[HEADER.FIELDS (date subject from content-type to cc bcc " +
                     "reply-to message-id references in-reply-to list-unsubscribe sender " +
                     K9MailLib.IDENTITY_HEADER + " " + K9MailLib.CHAT_HEADER + ")]"
             )
diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt
index b1beda25b..ff3e5b6df 100644
--- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt
+++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt
@@ -697,8 +697,8 @@ class RealImapFolderTest {
 
         verify(imapConnection).sendCommand(
             "UID FETCH 1 (UID INTERNALDATE RFC822.SIZE BODY.PEEK[HEADER.FIELDS " +
-                "(date subject from content-type to cc reply-to message-id references in-reply-to list-unsubscribe " +
-                "sender X-K9mail-Identity Chat-Version)])",
+                "(date subject from content-type to cc bcc reply-to message-id references in-reply-to " +
+                "list-unsubscribe sender X-K9mail-Identity Chat-Version)])",
             false
         )
     }
Repository: thundernest/k-9
Issue: Message buttons missing from top of screen after deleting message

### 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.307

### Where did you get the app from?

Google Play

### Android version

Android 13

### Device model

Pixel 6

### Steps to reproduce

Sometimes after I delete a message by tapping the delete button, when it displays the next message the buttons that are supposed to be above the message, for example the delete button I just tapped, disappear.

### Expected behavior

Buttons remain visible after deleting a message and the next is displayed

### Actual behavior

Buttons disappear

### Logs

Logs are only a few seconds long and don't show the time when this last happened, don't know why. When it happens again I'll try again to capture logs.

Changed files:
app/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewContainerFragment.kt

diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewContainerFragment.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewContainerFragment.kt
index 4501c2507..f5ffabb4d 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewContainerFragment.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewContainerFragment.kt
@@ -172,9 +172,7 @@ class MessageViewContainerFragment : Fragment() {
         val newPosition = viewPager.currentItem - 1
         return if (newPosition >= 0) {
             setActiveMessage(newPosition)
-
-            val smoothScroll = true
-            viewPager.setCurrentItem(newPosition, smoothScroll)
+            viewPager.setCurrentItem(newPosition, /* smoothScroll = */ false)
             true
         } else {
             false
@@ -185,9 +183,7 @@ class MessageViewContainerFragment : Fragment() {
         val newPosition = viewPager.currentItem + 1
         return if (newPosition < adapter.itemCount) {
             setActiveMessage(newPosition)
-
-            val smoothScroll = true
-            viewPager.setCurrentItem(newPosition, smoothScroll)
+            viewPager.setCurrentItem(newPosition, /* smoothScroll = */ false)
             true
         } else {
             false
Repository: thundernest/k-9
Issue: New K-9 version is crashing

### 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.500

### Where did you get the app from?

Other

### Android version

Android 7.0

### Device model

Lenovo K6 power

### Steps to reproduce

1. Update app
2. After some time I'll get constant notification of K-9 mail keeps stopping.

### Expected behavior

It should not crash.

### Actual behavior

After update, app continues to crash without reason so I had to downgrade 

### Logs

_No response_

Changed files:
app/core/src/main/java/com/fsck/k9/job/K9WorkerFactory.kt

diff --git a/app/core/src/main/java/com/fsck/k9/job/K9WorkerFactory.kt b/app/core/src/main/java/com/fsck/k9/job/K9WorkerFactory.kt
index 71af4cbf3..9251fb486 100644
--- a/app/core/src/main/java/com/fsck/k9/job/K9WorkerFactory.kt
+++ b/app/core/src/main/java/com/fsck/k9/job/K9WorkerFactory.kt
@@ -12,8 +12,8 @@ class K9WorkerFactory : WorkerFactory() {
         appContext: Context,
         workerClassName: String,
         workerParameters: WorkerParameters
-    ): ListenableWorker {
+    ): ListenableWorker? {
         val workerClass = Class.forName(workerClassName).kotlin
-        return getKoin().get(workerClass) { parametersOf(workerParameters) }
+        return getKoin().getOrNull(workerClass) { parametersOf(workerParameters) }
     }
 }
Repository: thundernest/k-9
Issue: Deleting account doesn't change current color correctly

### 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.704

### Where did you get the app from?

F-Droid

### Android version

12

### Device model

samsung galaxy s10e

### Steps to reproduce

Have account A color blue,
account B color green,
select account B, delete account B

### Expected behavior

on fall back to account A after deletion, the drawer's color should change from green to blue

### Actual behavior

Drawer's color stays green until reselecting account A

### Logs

_No response_

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

diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/K9Drawer.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/K9Drawer.kt
index b8ed58c40..a6f013d7c 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/K9Drawer.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/K9Drawer.kt
@@ -221,6 +221,11 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
     private fun setAccounts(displayAccounts: List<DisplayAccount>) {
         val oldSelectedBackgroundColor = selectedBackgroundColor
 
+        val isOpenedAccountStillAvailable = displayAccounts.any { it.account.uuid == openedAccountUuid }
+        if (!isOpenedAccountStillAvailable) {
+            openedAccountUuid = displayAccounts.first().account.uuid
+        }
+
         var newActiveProfile: IProfile? = null
         val accountItems = displayAccounts.map { displayAccount ->
             val account = displayAccount.account
Repository: thundernest/k-9
Issue: Message view: Account chip not displayed when viewing messages in a thread (from Unified Inbox)

### 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.600

### Where did you get the app from?

Google Play

### Android version

13

### Device model

_No response_

### Steps to reproduce

1. Go to Unified Inbox
2. Click on a message which is not in a message thread.
3. Enjoy the restyled message view.

1. Go to Unified Inbox
2. Click on a message which is part of a message thread - you'll be taken to the thread view
3. Click on a message in the thread view
4. Enjoy the "old" message view instead of the restyled one.

### Expected behavior

I would expect the new message view to be consistently seen in every message view.

### Actual behavior

When I click on a message, which is not in a message thread, in the Unified Inbox, I see the new message view, with indication at the top which account the message comes from.

When I click on a message in the Unified Inbox which takes me to the thread view (i.e. the view listing all messages from the same thread) and then click on the message, I still see the old message view (without the indication of the account). The account is shown in the thread view (at the top, but with a simple, unstyled display), but not in the final message view.

### Logs

_No response_

Changed files:
app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt, app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt

diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
index 08318bd17..40ce5cb5d 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
@@ -1089,6 +1089,7 @@ open class MessageList :
         showMessageViewPlaceHolder()
 
         val tmpSearch = LocalSearch().apply {
+            setId(search?.id)
             addAccountUuid(account.uuid)
             and(SearchField.THREAD_ID, threadRootId.toString(), SearchSpecification.Attribute.EQUALS)
         }
diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt
index 9c37d455a..de1f188b3 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt
@@ -157,7 +157,7 @@ class MessageListFragment :
         }
 
     val isShowAccountChip: Boolean
-        get() = !isSingleAccountMode
+        get() = isUnifiedInbox || !isSingleAccountMode
 
     override fun onAttach(context: Context) {
         super.onAttach(context)
Repository: thundernest/k-9
Issue: Problematic behavior with mailing lists

### 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.305

### Where did you get the app from?

Other

### Android version

Android 11 custom ROM

### Device model

Crosscall Core X4

### Steps to reproduce

Hello,

When I receive an email with a mailing list (known and not local) as recipient, I have the following behavior :
**Incomplete mail :** 
_Answer :_ just mail author (label)(normal behavior)
_Answer all :_ mail author (label) + list (label)(normal behavior)
**Complete mail :**
_Answer :_ list (mail without label) (abnormal behavior)
_Answer all :_ mail author (label)+ list twice (one with label, one without) (abnormal behavior)

### Expected behavior

See steps to reproduce

### Actual behavior

See steps to reproduce

### Logs

_No response_

Changed files:
mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt
mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt

diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt
index 6746d8905..26ff4103d 100644
--- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt
+++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt
@@ -543,7 +543,7 @@ internal class RealImapFolder(
             fetchFields.add("RFC822.SIZE")
             fetchFields.add(
                 "BODY.PEEK[HEADER.FIELDS (date subject from content-type to cc bcc " +
-                    "reply-to message-id references in-reply-to list-unsubscribe sender " +
+                    "reply-to message-id references in-reply-to list-post list-unsubscribe sender " +
                     K9MailLib.IDENTITY_HEADER + " " + K9MailLib.CHAT_HEADER + ")]",
             )
         }
diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt
index 27225051e..c87615f2c 100644
--- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt
+++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt
@@ -673,7 +673,7 @@ class RealImapFolderTest {
         verify(imapConnection).sendCommand(
             "UID FETCH 1 (UID INTERNALDATE RFC822.SIZE BODY.PEEK[HEADER.FIELDS " +
                 "(date subject from content-type to cc bcc reply-to message-id references in-reply-to " +
-                "list-unsubscribe sender X-K9mail-Identity Chat-Version)])",
+                "list-post list-unsubscribe sender X-K9mail-Identity Chat-Version)])",
             false,
         )
     }
Repository: thundernest/k-9
Issue: Message list footer shows "load up to X more" when it shouldn't

### 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.306-SNAPSHOT

### Where did you get the app from?

_No response_

### Android version

doesn't matter

### Device model

_No response_

### Steps to reproduce

1. Set up a demo account (demo@k9mail.example)
2. Open "Turing Awards" folder
3. Swipe down to refresh
4. Observe that the footer still reads "load up to X more"

Note: Performing any action that will trigger an update of the message list (e.g. marking a message as read) will remove the footer (because the correct "more messages" value will be fetched from the database).

### Expected behavior

The "load up to X more" footer should disappear when the folder sync is complete.

### Actual behavior

The "load up to X more" footer is still visible after the folder sync has finished.

### Logs

_No response_

Changed files:
app/core/src/main/java/com/fsck/k9/mailstore/NotifierMessageStore.kt

diff --git a/app/core/src/main/java/com/fsck/k9/mailstore/NotifierMessageStore.kt b/app/core/src/main/java/com/fsck/k9/mailstore/NotifierMessageStore.kt
index 488dbbffd..0a63f3076 100644
--- a/app/core/src/main/java/com/fsck/k9/mailstore/NotifierMessageStore.kt
+++ b/app/core/src/main/java/com/fsck/k9/mailstore/NotifierMessageStore.kt
@@ -58,6 +58,11 @@ class NotifierMessageStore(
         notifyChange()
     }
 
+    override fun setMoreMessages(folderId: Long, moreMessages: MoreMessages) {
+        messageStore.setMoreMessages(folderId, moreMessages)
+        notifyChange()
+    }
+
     private fun notifyChange() {
         localStore.notifyChange()
     }
Repository: thundernest/k-9
Issue: "Show next message after delete" no longer opens previous message when there is no next message

### 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.305

### Where did you get the app from?

F-Droid

### Android version

12

### Device model

Motorola g52

### Steps to reproduce

Prerequisite:
Set "Display next message after deletion" to on in General Settings/Interaction

1. Go to a mail folder
2. Set the order by date
3. Scoll down to the last item in the list
4. Open that mail
5. Delete that mail


### Expected behavior

In the previous version the system displyed the next mail (aka. the more recent one)
Note, I might remember there was an arrow in the header, to switch direction if I wanted to go one mail down or up when in the mail reading pane.

Please pull this useful function back.


### Actual behavior

The system displays the list instead of the next mail (the more recent one)

The direction change arrow is also missing now.

### Logs

_No response_

Changed files:
app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt

diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
index fbb37fdfd..a78a33697 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
@@ -1198,10 +1198,16 @@ open class MessageList :
     }
 
     private fun showLogicalNextMessage(): Boolean {
-        return when (lastDirection) {
+        val couldMoveInLastDirection = when (lastDirection) {
             Direction.NEXT -> showNextMessage()
             Direction.PREVIOUS -> showPreviousMessage()
         }
+
+        return if (couldMoveInLastDirection) {
+            true
+        } else {
+            showNextMessage() || showPreviousMessage()
+        }
     }
 
     override fun setProgress(enable: Boolean) {
Repository: thundernest/k-9
Issue: Search input field is focused when starting the app

### 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.305

### Where did you get the app from?

_No response_

### Android version

Android 11, MIUI 12.5.1

### Device model

_No response_

### Steps to reproduce

1. Start the app using the app icon

### Expected behavior

When starting the app the search view should be collapsed into the magnifying glass icon.

### Actual behavior

On some devices, when starting the app, the search view will be expanded and focused, i.e. the keyboard is showing.

See https://forum.k9mail.app/t/search-bar-displayed-at-first-launch/5425

### Logs

_No response_

Changed files:
app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt

diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
index addb16a9f..fbb37fdfd 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
@@ -588,7 +588,7 @@ open class MessageList :
 
         messageViewOnly = savedInstanceState.getBoolean(STATE_MESSAGE_VIEW_ONLY)
         messageListWasDisplayed = savedInstanceState.getBoolean(STATE_MESSAGE_LIST_WAS_DISPLAYED)
-        initialSearchViewIconified = savedInstanceState.getBoolean(STATE_SEARCH_VIEW_ICONIFIED)
+        initialSearchViewIconified = savedInstanceState.getBoolean(STATE_SEARCH_VIEW_ICONIFIED, true)
         initialSearchViewQuery = savedInstanceState.getString(STATE_SEARCH_VIEW_QUERY)
     }
 
@@ -970,8 +970,8 @@ open class MessageList :
             }
         })
 
-        searchView.isIconified = initialSearchViewIconified
         searchView.setQuery(initialSearchViewQuery, false)
+        searchView.isIconified = initialSearchViewIconified
 
         this.searchView = searchView
     }
Repository: thundernest/k-9
Issue: Attempting to create new identity crashes app

K-9 mail configured with single IMAP account with just the default identity.  Attempting to add a new identity crashes the app and brings up "K-9 Mail keeps stopping" dialog box.

### Expected behavior
Settings->Account->Sending Mail->Manage Identities->New identity should allow adding a new identity.

### Actual behavior
Click the New Identity button once brings you back to Sending Mail page.  Going into "Manage Identities" and clicking new identity again brings up the  "K-9 Mail keeps stopping" dialog box.

### Steps to reproduce
See above

### Environment
K-9 Mail version: 5.701

Android version:  10

Account type (IMAP, POP3, WebDAV/Exchange): IMAP

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

diff --git a/app/ui/src/main/java/com/fsck/k9/activity/EditIdentity.kt b/app/ui/src/main/java/com/fsck/k9/activity/EditIdentity.kt
index 41e62d039..273e4a033 100644
--- a/app/ui/src/main/java/com/fsck/k9/activity/EditIdentity.kt
+++ b/app/ui/src/main/java/com/fsck/k9/activity/EditIdentity.kt
@@ -15,20 +15,16 @@ class EditIdentity : K9Activity() {
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
+        setLayout(R.layout.edit_identity)
 
-        identity = intent.getParcelableExtra(EXTRA_IDENTITY)
         identityIndex = intent.getIntExtra(EXTRA_IDENTITY_INDEX, -1)
         val accountUuid = intent.getStringExtra(EXTRA_ACCOUNT)
         account = Preferences.getPreferences(this).getAccount(accountUuid)
 
-        if (identityIndex == -1) {
-            identity = Identity()
-        }
-
-        setLayout(R.layout.edit_identity)
-
-        savedInstanceState?.getParcelable<Identity>(EXTRA_IDENTITY)?.let {
-            identity = it
+        identity = when {
+            savedInstanceState != null -> savedInstanceState.getParcelable(EXTRA_IDENTITY) ?: error("Missing state")
+            identityIndex != -1 -> intent.getParcelableExtra(EXTRA_IDENTITY) ?: error("Missing argument")
+            else -> Identity()
         }
 
         description.setText(identity.description)
Repository: thundernest/k-9
Issue: Download Complete Message-Connection Error

Version 5.7, Android 10 Build QP1A.191105.003
On a POP3 SSL connection, a message with attachments displays the Download Complete Message as this email has always done (daily click report with attached CSV and PDF files that are not that large).  

New with 5.7: touching the Download Complete Message button results in  small rounded pop-up message stating "Connection Error".  Connected to both wifi and network.

Thanks for 5.7 looking great so far...
### Expected behavior
Spends a few seconds downloading and I touch the PDF to view the report.

### Actual behavior
Displays connection error pop-up

### Steps to reproduce
1. Open a moderate size email with a CSV and PDF attachment
2. Touch the Download Complete Message 

### Environment
K-9 Mail version:
5.7
Android version:
10 Build QP1A.191105.003
Account type (IMAP, POP3, WebDAV/Exchange):
POP3 SSL

Please take some time to [retrieve logs](https://github.com/k9mail/k-9/wiki/LoggingErrors) and attach them here:
Sorry not at PC, let me know if this defies simple repro and I can get you the trace...

Changed files:
backend/pop3/src/main/java/com/fsck/k9/backend/pop3/CommandFetchMessage.kt

diff --git a/backend/pop3/src/main/java/com/fsck/k9/backend/pop3/CommandFetchMessage.kt b/backend/pop3/src/main/java/com/fsck/k9/backend/pop3/CommandFetchMessage.kt
index 055a04a49..e6a1775ad 100644
--- a/backend/pop3/src/main/java/com/fsck/k9/backend/pop3/CommandFetchMessage.kt
+++ b/backend/pop3/src/main/java/com/fsck/k9/backend/pop3/CommandFetchMessage.kt
@@ -1,6 +1,7 @@
 package com.fsck.k9.backend.pop3
 
 import com.fsck.k9.mail.FetchProfile
+import com.fsck.k9.mail.Folder.OPEN_MODE_RW
 import com.fsck.k9.mail.Message
 import com.fsck.k9.mail.store.pop3.Pop3Store
 
@@ -9,8 +10,9 @@ internal class CommandFetchMessage(private val pop3Store: Pop3Store) {
     fun fetchMessage(folderServerId: String, messageServerId: String, fetchProfile: FetchProfile): Message {
         val folder = pop3Store.getFolder(folderServerId)
         try {
-            val message = folder.getMessage(messageServerId)
+            folder.open(OPEN_MODE_RW)
 
+            val message = folder.getMessage(messageServerId)
             folder.fetch(listOf(message), fetchProfile, null)
 
             return message
Repository: thundernest/k-9
Issue: Fix log output of `SmtpResponseParser`

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

2205202769770bc37feb98414bb8a1ae084b9c98

### Where did you get the app from?

_No response_

### Android version

all

### Device model

_No response_

### Steps to reproduce

See log attached to #6062

### Expected behavior

Have nice log output.

### Actual behavior

- The log contains "SMTP response data on parser error" twice. Find out why that is and if it needs to be fixed.
- `SmtpResponseParser.readHelloResponse()` doesn't clear `logBuffer`, so the greeting appears under "SMTP response data on parser error" even though it was parsed without error.

When fixing this please add tests to make sure this doesn't happen again.

### Logs

_No response_

Changed files:
mail/protocols/smtp/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpResponseParser.kt
mail/protocols/smtp/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpResponseParserTest.kt

diff --git a/mail/protocols/smtp/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpResponseParser.kt b/mail/protocols/smtp/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpResponseParser.kt
index a7ceefaa1..5428e12b7 100644
--- a/mail/protocols/smtp/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpResponseParser.kt
+++ b/mail/protocols/smtp/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpResponseParser.kt
@@ -33,6 +33,8 @@ internal class SmtpResponseParser(
     }
 
     fun readHelloResponse(): SmtpHelloResponse {
+        logBuffer.clear()
+
         val replyCode = readReplyCode()
 
         if (replyCode != 250) {
diff --git a/mail/protocols/smtp/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpResponseParserTest.kt b/mail/protocols/smtp/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpResponseParserTest.kt
index a9d4d3e62..75923e5f1 100644
--- a/mail/protocols/smtp/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpResponseParserTest.kt
+++ b/mail/protocols/smtp/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpResponseParserTest.kt
@@ -219,6 +219,30 @@ class SmtpResponseParserTest {
             .isEqualTo("Ignoring EHLO keyword line: KEYWORD para${"\\t"}meter")
     }
 
+    @Test
+    fun `error in EHLO response after successfully reading greeting`() {
+        val input = """
+            220 Greeting
+            INVALID
+        """.toPeekableInputStream()
+        val parser = SmtpResponseParser(logger, input)
+        parser.readGreeting()
+
+        assertFailsWithMessage("Unexpected character: I (73)") {
+            parser.readHelloResponse()
+        }
+
+        assertThat(logger.logEntries).containsExactly(
+            LogEntry(
+                throwable = null,
+                message = """
+                    SMTP response data on parser error:
+                    I
+                """.trimIndent()
+            )
+        )
+    }
+
     @Test
     fun `positive response`() {
         val input = "200 OK".toPeekableInputStream()
Repository: thundernest/k-9
Issue: MessageCompose activity is not always enabled when it should

Use `Preferences.getAccounts()` instead of `getAvailableAccounts()` when enabling components in `Core.setServicesEnabled()`.

Changed files:
app/core/src/main/java/com/fsck/k9/Core.kt

diff --git a/app/core/src/main/java/com/fsck/k9/Core.kt b/app/core/src/main/java/com/fsck/k9/Core.kt
index c5fd3d39c..003608fe8 100644
--- a/app/core/src/main/java/com/fsck/k9/Core.kt
+++ b/app/core/src/main/java/com/fsck/k9/Core.kt
@@ -46,7 +46,7 @@ object Core : EarlyInit {
     @JvmStatic
     fun setServicesEnabled(context: Context) {
         val appContext = context.applicationContext
-        val acctLength = Preferences.getPreferences(appContext).availableAccounts.size
+        val acctLength = Preferences.getPreferences(appContext).accounts.size
         val enable = acctLength > 0
 
         setServicesEnabled(appContext, enable)
Repository: thundernest/k-9
Issue: Re-opening via App-Icon does not remember last state.

**Describe the bug**
When the app is running open in the background, say with an email opened and one uses the app drawer/home screen icon, the app will open up and return to the start view (inbox of the default account or whatever is set) instead  of  showing the last opened view.

**To Reproduce**
Steps to reproduce the behavior:
1. Open app and navigate to random view (e.g. open any Email).
2. Go to the android home screen (i.e. minimize K9).
3. Re-open K9 from the "active apps" screen.
4. The app will open with the last state (i.e. the email we opened in 1.).
5. Go to home screen again.
6. Open K9 via home screen or app drawer icon.
7. The app opens with the default start view instead of the previously opened view.

**Expected behavior**
If the app window is already running in the background, I would expect all entry points to show the same app view, which is the currently active view.
The current behaviour in step 6-7 rather resembles a restart of the app then a re-open.
Also, it is quite easy to navigate back to the start page from any point in the app, but can be quite difficult to return to the previously opened mail/view from the start page.

**Environment**
 - K-9 Mail version: 5.8.03
 - Android version: 11
 - Device: Google Pixel 3a (likely all)
 - Account type: all



Changed files:
app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt

diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
index 29a44645d..a244c022d 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt
@@ -132,6 +132,16 @@ open class MessageList :
     public override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
 
+        // If the app's main task was not created using the default launch intent (e.g. from a notification, a widget,
+        // or a shortcut), using the app icon to "launch" the app will create a new MessageList instance instead of only
+        // bringing the app's task to the foreground. We catch this situation here and simply finish the activity. This
+        // will bring the task to the foreground, showing the last active screen.
+        if (intent.action == Intent.ACTION_MAIN && intent.hasCategory(Intent.CATEGORY_LAUNCHER) && !isTaskRoot) {
+            Timber.v("Not displaying MessageList. Only bringing the app task to the foreground.")
+            finish()
+            return
+        }
+
         val accounts = preferences.accounts
         deleteIncompleteAccounts(accounts)
         val hasAccountSetup = accounts.any { it.isFinishedSetup }
Repository: thundernest/k-9
Issue: App crashes, when searching for a word that starts with a hyphen

When I open a folder and press "search", then enter any searchword that starts with a hyphen ("-anything" for example) the app crashes immediately after pressing enter.

### Expected behavior
Give me a list of messages containing the given phrase.

### Actual behavior
App crashes

### Steps to reproduce
1. Open inbox
2. press the magnifying glass icon
3. enter "-something" and press Enter

### Environment
K-9 Mail version: 5.600

Android version: 8.0.0 / 7.1.1

Account type (IMAP, POP3, WebDAV/Exchange): IMAP


Changed files:
app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLoader.kt

diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLoader.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLoader.kt
index 304d4bcfe..bbb06c667 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLoader.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLoader.kt
@@ -1,10 +1,14 @@
 package com.fsck.k9.ui.messagelist
 
+import android.annotation.SuppressLint
 import android.content.ContentResolver
 import android.database.Cursor
+import android.database.MatrixCursor
+import android.database.sqlite.SQLiteException
 import android.net.Uri
 import com.fsck.k9.Account
 import com.fsck.k9.Account.SortType
+import com.fsck.k9.K9
 import com.fsck.k9.Preferences
 import com.fsck.k9.fragment.MLFProjectionInfo
 import com.fsck.k9.fragment.MessageListFragmentComparators.ArrivalComparator
@@ -26,6 +30,7 @@ import com.fsck.k9.search.SqlQueryBuilder
 import com.fsck.k9.search.getAccounts
 import java.util.ArrayList
 import java.util.Comparator
+import timber.log.Timber
 
 class MessageListLoader(
     private val preferences: Preferences,
@@ -62,6 +67,7 @@ class MessageListLoader(
         return MessageListInfo(messageListItems, hasMoreMessages)
     }
 
+    @SuppressLint("Recycle")
     private fun loadMessageListForAccount(account: Account, config: MessageListConfig): Cursor? {
         val accountUuid = account.uuid
         val threadId: String? = getThreadId(config.search)
@@ -110,7 +116,17 @@ class MessageListLoader(
 
         val sortOrder: String = buildSortOrder(config)
 
-        return contentResolver.query(uri, projection, selection, selectionArgs, sortOrder)
+        return try {
+            contentResolver.query(uri, projection, selection, selectionArgs, sortOrder)
+        } catch (e: SQLiteException) {
+            Timber.e(e, "Error querying EmailProvider")
+
+            if (K9.DEVELOPER_MODE && e.message?.contains("malformed MATCH expression") == false) {
+                throw e
+            }
+
+            return MatrixCursor(projection)
+        }
     }
 
     private fun getThreadId(search: LocalSearch): String? {
Repository: thundernest/k-9
Issue: Inbox list shows name of recipient

**Describe the bug**
If same IMAP folder is selected for both Sent and Inbox folders then message list in Inbox shows recipient name.

**Expected behavior**
Inbox message list should always show sender name.

**Environment (please complete the following information):**
 - K-9 Mail version: 5.722


Changed files:
app/ui/legacy/src/main/java/com/fsck/k9/ui/helper/DisplayAddressHelper.kt

diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/helper/DisplayAddressHelper.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/helper/DisplayAddressHelper.kt
index e323d602b..7320cd582 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/helper/DisplayAddressHelper.kt
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/helper/DisplayAddressHelper.kt
@@ -5,6 +5,10 @@ import com.fsck.k9.Account
 object DisplayAddressHelper {
     fun shouldShowRecipients(account: Account, folderId: Long): Boolean {
         return when (folderId) {
+            account.inboxFolderId -> false
+            account.archiveFolderId -> false
+            account.spamFolderId -> false
+            account.trashFolderId -> false
             account.sentFolderId -> true
             account.draftsFolderId -> true
             account.outboxFolderId -> true
Repository: cashapp/sqldelight
Issue: Uncaught ReferenceError: SqlJs is not defined

SQLDelight version: 1.5.0-SNAPSHOT
Application OS: Chrome, compiled using Kotlin/JS IR compiler

When using the sqljs driver everything compiles fine, but at runtime an Uncaught ReferenceError is thrown.
The error comes from these lines in the bundled js output:
```js
// ...
// Unrelated js code
}(this, function (_, initSqlJs, $module$_js_joda_core) {
  var Database = SqlJs.Database;
  var Statement = SqlJs.Statement;
// More module initialization code
// ...
```
`SqlJs` is never defined. This also happens if the `:sqljs-driver` module is modified to produce an IR binary. The resulting js bundle has the same set of lines as above.

This only seems to happen with the IR compiler so it might be an issue in either webpack or the compiler, but I figured I'd start by opening an issue here.

Changed files:
drivers/sqljs-driver/src/main/kotlin/com/squareup/sqldelight/drivers/sqljs/sqljs.SqlJs.kt

diff --git a/drivers/sqljs-driver/src/main/kotlin/com/squareup/sqldelight/drivers/sqljs/sqljs.SqlJs.kt b/drivers/sqljs-driver/src/main/kotlin/com/squareup/sqldelight/drivers/sqljs/sqljs.SqlJs.kt
index 49c483ac2..c2b046162 100644
--- a/drivers/sqljs-driver/src/main/kotlin/com/squareup/sqldelight/drivers/sqljs/sqljs.SqlJs.kt
+++ b/drivers/sqljs-driver/src/main/kotlin/com/squareup/sqldelight/drivers/sqljs/sqljs.SqlJs.kt
@@ -1,4 +1,5 @@
-@file:JsQualifier("SqlJs")
+@file:JsModule("sql.js")
+@file:JsNonModule
 @file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS", "EXTERNAL_DELEGATION")
 package com.squareup.sqldelight.drivers.sqljs