mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-24 15:11:03 +00:00
Limit text size / number of links
This commit is contained in:
parent
77440f7181
commit
18c77ed9c6
2 changed files with 14 additions and 3 deletions
|
@ -74,9 +74,11 @@ import static androidx.core.text.HtmlCompat.FROM_HTML_SEPARATOR_LINE_BREAK_LIST_
|
|||
import static androidx.core.text.HtmlCompat.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE;
|
||||
|
||||
public class HtmlHelper {
|
||||
static final int PREVIEW_SIZE = 250;
|
||||
static final int PREVIEW_SIZE = 250; // characters
|
||||
|
||||
private static final int TRACKING_PIXEL_SURFACE = 25;
|
||||
private static final int MAX_LINKS = 50;
|
||||
private static final int MAX_SIZE = 50 * 1024; // characters
|
||||
private static final int TRACKING_PIXEL_SURFACE = 25; // pixels
|
||||
|
||||
private static final List<String> heads = Collections.unmodifiableList(Arrays.asList(
|
||||
"h1", "h2", "h3", "h4", "h5", "h6", "p", "ol", "ul", "table", "br", "hr"));
|
||||
|
@ -124,6 +126,10 @@ public class HtmlHelper {
|
|||
}
|
||||
}
|
||||
|
||||
int links = parsed.select("a").size();
|
||||
if (links > MAX_LINKS || parsed.text().length() > MAX_SIZE)
|
||||
return "<strong>" + context.getString(R.string.title_hint_too_complex) + "</strong>";
|
||||
|
||||
Whitelist whitelist = Whitelist.relaxed()
|
||||
.addTags("hr", "abbr")
|
||||
.removeTags("col", "colgroup", "thead", "tbody")
|
||||
|
@ -266,6 +272,8 @@ public class HtmlHelper {
|
|||
PatternsCompat.AUTOLINK_WEB_URL.pattern());
|
||||
|
||||
NodeTraversor.traverse(new NodeVisitor() {
|
||||
private int alinks = links;
|
||||
|
||||
@Override
|
||||
public void head(Node node, int depth) {
|
||||
if (node instanceof TextNode) {
|
||||
|
@ -294,7 +302,7 @@ public class HtmlHelper {
|
|||
" " + matcher.start() + "..." + matcher.end() + "/" + text.length() +
|
||||
" linked=" + linked + " email=" + email);
|
||||
|
||||
if (linked)
|
||||
if (linked || alinks >= MAX_LINKS)
|
||||
span.appendText(text.substring(pos, matcher.end()));
|
||||
else {
|
||||
span.appendText(text.substring(pos, matcher.start()));
|
||||
|
@ -303,6 +311,8 @@ public class HtmlHelper {
|
|||
a.attr("href", (email ? "mailto:" : "") + matcher.group());
|
||||
a.text(matcher.group());
|
||||
span.appendChild(a);
|
||||
|
||||
alinks++;
|
||||
}
|
||||
|
||||
pos = matcher.end();
|
||||
|
|
|
@ -756,6 +756,7 @@
|
|||
<string name="title_hint_message_selection">Long press a message to start selecting multiple messages</string>
|
||||
<string name="title_hint_sync">Downloading messages can take some time, depending on the speed of the provider, internet connection and device and on the number of messages. While downloading messages the app might respond slower.</string>
|
||||
<string name="title_hint_image_link">Image link</string>
|
||||
<string name="title_hint_too_complex">Message too large or too complex to display</string>
|
||||
<string name="title_hint_tracking_image">Tracking image %1$sx%2$s</string>
|
||||
<string name="title_hint_contact_actions">Long press for options</string>
|
||||
|
||||
|
|
Loading…
Reference in a new issue