diff --git a/k9mail/src/main/java/com/fsck/k9/message/html/EmailSectionExtractor.kt b/k9mail/src/main/java/com/fsck/k9/message/html/EmailSectionExtractor.kt index eed0aea74..e995d8363 100644 --- a/k9mail/src/main/java/com/fsck/k9/message/html/EmailSectionExtractor.kt +++ b/k9mail/src/main/java/com/fsck/k9/message/html/EmailSectionExtractor.kt @@ -96,12 +96,10 @@ class EmailSectionExtractor private constructor(val text: String) { } private fun completeLastSection() { - if (!isStartOfLine) { - if (quoteDepth == 0) { - sectionBuilder.addSegment(0, sectionStartIndex, text.length) - } else { - sectionBuilder.addSegment(spaces, startOfContentIndex, text.length) - } + if (quoteDepth == 0) { + sectionBuilder.addSegment(0, sectionStartIndex, text.length) + } else if (!isStartOfLine) { + sectionBuilder.addSegment(spaces, startOfContentIndex, text.length) } appendSection() diff --git a/k9mail/src/test/java/com/fsck/k9/message/html/EmailSectionExtractorTest.kt b/k9mail/src/test/java/com/fsck/k9/message/html/EmailSectionExtractorTest.kt index 1b00df103..bce97ac1f 100644 --- a/k9mail/src/test/java/com/fsck/k9/message/html/EmailSectionExtractorTest.kt +++ b/k9mail/src/test/java/com/fsck/k9/message/html/EmailSectionExtractorTest.kt @@ -26,6 +26,19 @@ class EmailSectionExtractorTest { } } + @Test + fun simpleMessageEndingWithTwoNewlines() { + val message = "Hello\n\n" + + val sections = EmailSectionExtractor.extract(message) + + assertThat(sections.size).isEqualTo(1) + with(sections[0]) { + assertThat(quoteDepth).isEqualTo(0) + assertThat(toString()).isEqualTo(message) + } + } + @Test fun quoteFollowedByReply() { val message = """ @@ -81,6 +94,24 @@ class EmailSectionExtractorTest { } } + @Test + fun quoteEndingWithEmptyLineButNoNewline() { + val message = """ + > Quoted text + > """.trimIndent() + + val sections = EmailSectionExtractor.extract(message) + + assertThat(sections.size).isEqualTo(1) + with(sections[0]) { + assertThat(quoteDepth).isEqualTo(1) + // Note: "Quoted text\n\n" would be a better representation of the quoted text. The goal of this test is + // not to preserve the current behavior of only ending in one newline, but to make sure we don't add the + // last line twice. + assertThat(toString()).isEqualTo("Quoted text\n") + } + } + @Test fun chaosQuoting() { val message = """