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

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_


Discussion hints:
nan

Pull request: Clear log buffer before reading EHLO response
Fixes #6063

Test command: ./gradlew :mail:protocols:smtp:test --tests "com.fsck.k9.mail.transport.smtp.SmtpResponseParserTest"

Fix patch:
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 a7ceefaa101..5428e12b7e4 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) {


Test patch:
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 a9d4d3e62ba..75923e5f1b7 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()