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

Issue:
<a> "name" attribute is sanitized
### 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.202

### Where did you get the app from?

Other

### Android version

Havoc OS 4 (Android 11)

### Device model

Oneplus 3T

### Steps to reproduce

teltarif.de sends newsletters with a table of contents at the top.

In Thunderbird I can click on these headlines and it forwards me to the corresponding article/section down below.

K9 currently sanitizes name attributes of links though, so the webview(?) component doesn't know where to move the viewport to (no link with a corresponding name attribute below)

`<A NAME="a1"></A>`
is sanitized to
`<a></a>`

The corresponding link in the table of contents looks like this:
`<a href="#a1">`
You've probably seen countless websites like wikipedia who use this feature as well.
usually they use the id of an element though not an actual <a> tag with a name attribute, which is obsolete in newer html versions, I think (not that it matters for mails)

### Expected behavior

K9 shouldn't remove the attribute

### Actual behavior

K9 removes the attribute

### Logs

_No response_
align=center is sanitized
### 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.202

### Where did you get the app from?

Other

### Android version

Havoc OS 4 (Android 11)

### Device model

Oneplus 3T

### Steps to reproduce

`<div class="alignment" align="center">`
is sanitized by the html cleaner code to
`<div class="alignment">`

(I verified this using the html-cleaner cli)

The div with "align center" is used to center a link in the mail (<a> that looks like a button)

I attached screenshots in the following sections to showcase the behaviour

### Expected behavior

![grafik](https://user-images.githubusercontent.com/5685512/184463886-ea762804-2fd9-41c6-b75d-8cfc2478ea1e.png)

### Actual behavior

![grafik](https://user-images.githubusercontent.com/5685512/184463905-7b3f939d-b84b-4950-a2bb-8fa0fd1ae698.png)


### Logs

_No response_


Discussion hints:

Pull request: HTML sanitizer updates
Fixes #6240
Fixes #6241

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 80fa043e840..5697b115c4f 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
@@ -15,6 +15,8 @@ internal class BodyCleaner {
         val allowList = Safelist.relaxed()
             .addTags("font", "hr", "ins", "del", "center", "map", "area", "title")
             .addAttributes("font", "color", "face", "size")
+            .addAttributes("a", "name")
+            .addAttributes("div", "align")
             .addAttributes(
                 "table", "align", "background", "bgcolor", "border", "cellpadding", "cellspacing",
                 "width"


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 12ea9e797b9..8720a3273d5 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
@@ -409,6 +409,42 @@ class HtmlSanitizerTest {
         )
     }
 
+    @Test
+    fun `should keep 'align' attribute on 'div' element`() {
+        val html = """<div align="center">text</div>"""
+
+        val result = htmlSanitizer.sanitize(html)
+
+        assertThat(result.toCompactString()).isEqualTo(
+            """
+            <html>
+            <head></head>
+            <body>
+            <div align="center">text</div>
+            </body>
+            </html>
+            """.trimIndent().trimLineBreaks()
+        )
+    }
+
+    @Test
+    fun `should keep 'name' attribute on 'a' element`() {
+        val html = """<a name="something">"""
+
+        val result = htmlSanitizer.sanitize(html)
+
+        assertThat(result.toCompactString()).isEqualTo(
+            """
+            <html>
+            <head></head>
+            <body>
+            <a name="something"></a>
+            </body>
+            </html>
+            """.trimIndent().trimLineBreaks()
+        )
+    }
+
     private fun Document.toCompactString(): String {
         outputSettings()
             .prettyPrint(false)