From a1eb60659faf054ee78e70d99479d0bfcd6a79f9 Mon Sep 17 00:00:00 2001 From: dab246 Date: Tue, 1 Aug 2023 10:40:10 +0700 Subject: [PATCH] TF-2047 Add `adr` for sanitize and autolink html when type is text/plain (cherry picked from commit 5e5a389c7ebc04a4aecf5eca94350e76dfd695a6) --- ...k-when-type-is-text-plain-in-email-view.md | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 docs/adr/0030-fix-can-not-see-link-when-type-is-text-plain-in-email-view.md diff --git a/docs/adr/0030-fix-can-not-see-link-when-type-is-text-plain-in-email-view.md b/docs/adr/0030-fix-can-not-see-link-when-type-is-text-plain-in-email-view.md new file mode 100644 index 000000000..a378037ce --- /dev/null +++ b/docs/adr/0030-fix-can-not-see-link-when-type-is-text-plain-in-email-view.md @@ -0,0 +1,39 @@ +# 30. Fix can not see link when type is text/plain in email view + +Date: 2023-08-01 + +## Status + +- Issue: + +[1881](https://github.com/linagora/tmail-flutter/issues/1881) +[2047](https://github.com/linagora/tmail-flutter/issues/2047) + +## Context + +- When `Content-Type=Text/Plain` the `url` and `email-addreess` links are not automatically `highlighted`. +- Some `url` links are `highlighted` when clicking, opening the content in the email view itself does not create a new tab. + +## Root cause + +- Because we perform `html escape` before creating `autolink`, it makes lost tags undetectable. Moreover, the detect function is ignored in some cases + +## Decision + +- Use linkify to detect `url/email/text` and return a list of corresponding elements. +```dart + final elements = linkify(inputText); +``` + +- If element is `TextElement` we perform html escape for it. +- If element is `UrlElement` or `EmailElement` we make html link tag (``) for it. +```dart + String _buildLinkTag({required String link, required String value}) { + return '$value'; + } +``` + +## Consequences + +- Accurately detect and fully highlight `url` and `email-address` links in email body when `Content-Type=Text/plain` +- Automatically open new tab when clicking on `url` link and open composer when clicking on `email-address`