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

Issue:
MS Xbox Mail issue - Sanitizer deletes stylesheet
### 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.7.10

### Where did you get the app from?

Other

### Android version

13

### Device model

Pixel 7 Pro

### Steps to reproduce

[eml.zip](https://github.com/thundernest/k-9/files/12558805/eml.zip)

### Expected behavior

The stylesheets get used for rendering (not deleted).
The Header is readable (displayed in separate lines not overlapping itself)

### Actual behavior

The `<style>` elements get deleted by the sanitizer, because they are wrapped within `<table>s` (for whatever reason).
These tables are within the `<head>` tag which in return also makes the sanitizer create the body (too) early. (compared to the actual body tag in the mail)

![grafik](https://github.com/thundernest/k-9/assets/5685512/fda1ed62-9482-45ee-82ca-079a444243b3)


### Logs

_No response_


Discussion hints:
> These tables are within the <head> tag which in return also makes the sanitizer create the body (too) early. (compared to the actual body tag in the mail)

This works as intended. The HTML parser creates an `html`,  a `head`, and a `body` element when it encounters the first `<table>` tag.

`<style>` tags are supported inside `<body>`. So we'll add them to our allow list.

Pull request: Allow `<style>` tags inside the HTML body
Fixes #7163

Test command: ./gradlew :app:html-cleaner:test --tests "app.k9mail.html.cleaner.HtmlSanitizerTest"

Fix patch:
diff --git a/app/html-cleaner/src/main/java/app/k9mail/html/cleaner/BodyCleaner.kt b/app/html-cleaner/src/main/java/app/k9mail/html/cleaner/BodyCleaner.kt
index 4fb58c28522..9102f3a5ec7 100644
--- a/app/html-cleaner/src/main/java/app/k9mail/html/cleaner/BodyCleaner.kt
+++ b/app/html-cleaner/src/main/java/app/k9mail/html/cleaner/BodyCleaner.kt
@@ -13,7 +13,7 @@ internal class BodyCleaner {
 
     init {
         val allowList = Safelist.relaxed()
-            .addTags("font", "hr", "ins", "del", "center", "map", "area", "title", "tt", "kbd", "samp", "var")
+            .addTags("font", "hr", "ins", "del", "center", "map", "area", "title", "tt", "kbd", "samp", "var", "style")
             .addAttributes("font", "color", "face", "size")
             .addAttributes("a", "name")
             .addAttributes("div", "align")


Test patch:
diff --git a/app/html-cleaner/src/test/java/app/k9mail/html/cleaner/HtmlSanitizerTest.kt b/app/html-cleaner/src/test/java/app/k9mail/html/cleaner/HtmlSanitizerTest.kt
index 51f92121374..bd818122e86 100644
--- a/app/html-cleaner/src/test/java/app/k9mail/html/cleaner/HtmlSanitizerTest.kt
+++ b/app/html-cleaner/src/test/java/app/k9mail/html/cleaner/HtmlSanitizerTest.kt
@@ -485,6 +485,23 @@ class HtmlSanitizerTest {
         assertThat(result.toCompactString()).isEqualTo(html)
     }
 
+    @Test
+    fun `should keep 'style' element in body`() {
+        val html =
+            """
+            <html>
+              <head></head>
+              <body>
+                <style>.test { color: #000 }</style>
+              </body>
+            </html>
+            """.compactHtml()
+
+        val result = htmlSanitizer.sanitize(html)
+
+        assertThat(result.toCompactString()).isEqualTo(html)
+    }
+
     private fun assertTagsNotStripped(element: String) {
         val html = """<$element>some text</$element>"""