diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java
index 413383d1b9..8f301f30f9 100644
--- a/app/src/main/java/eu/faircode/email/HtmlHelper.java
+++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java
@@ -131,9 +131,15 @@ public class HtmlHelper {
int end = 0;
while (matcher.find()) {
sb.append(Html.escapeHtml(text.substring(end, matcher.start())));
- String ref = Html.escapeHtml(matcher.group());
+
+ String url = matcher.group();
+ if (url.endsWith(")") && !url.contains("(")) {
+ url = url.substring(0, url.length() - 1);
+ }
+
+ String ref = Html.escapeHtml(url);
sb.append(String.format("%s", ref, ref));
- end = matcher.end();
+ end = matcher.start() + url.length();
}
sb.append(text.substring(end));
return sb.toString();
diff --git a/app/src/test/java/eu/faircode/email/HtmlHelperTest.java b/app/src/test/java/eu/faircode/email/HtmlHelperTest.java
index 9e452a6006..4438bb66fc 100644
--- a/app/src/test/java/eu/faircode/email/HtmlHelperTest.java
+++ b/app/src/test/java/eu/faircode/email/HtmlHelperTest.java
@@ -120,10 +120,10 @@ public class HtmlHelperTest {
testAutolink(
"See my homepage (at https://example.org), with lots of examples.",
- // FIXME: The URL doesn't contain an opening parenthesis, therefore
+ // This URL doesn't contain an opening parenthesis, therefore
// the closing parenthesis probably also doesn't belong to it.
- "See my homepage (at " +
- "https://example.org), with lots of examples."
+ "See my homepage (at " +
+ "https://example.org), with lots of examples."
);
// The terminating sequence of a base64-encoded URL parameter is always