Mark tracking images

This commit is contained in:
M66B 2019-03-10 17:32:32 +00:00
parent dec43f8da2
commit f2a1828e3a
5 changed files with 17 additions and 6 deletions

View File

@ -103,7 +103,7 @@ public class ActivityEml extends ActivityBase {
result.parts = HtmlHelper.fromHtml(sb.toString());
result.html = parts.getHtml(context);
result.body = HtmlHelper.fromHtml(HtmlHelper.sanitize(result.html, true));
result.body = HtmlHelper.fromHtml(HtmlHelper.sanitize(context, result.html, true));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
mmessage.writeTo(bos);

View File

@ -1653,7 +1653,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
final boolean show_quotes = properties.getValue("quotes", message.id);
final boolean show_images = properties.getValue("images", message.id);
return HtmlHelper.fromHtml(HtmlHelper.sanitize(body, show_quotes), new Html.ImageGetter() {
return HtmlHelper.fromHtml(HtmlHelper.sanitize(context, body, show_quotes), new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
Drawable image = HtmlHelper.decodeImage(source, context, message.id, show_images);

View File

@ -2336,7 +2336,7 @@ public class FragmentCompose extends FragmentBase {
Spanned spannedReference = null;
File refFile = EntityMessage.getRefFile(context, id);
if (refFile.exists()) {
String quote = HtmlHelper.sanitize(Helper.readText(refFile), true);
String quote = HtmlHelper.sanitize(context, Helper.readText(refFile), true);
Spanned spannedQuote = HtmlHelper.fromHtml(quote,
new Html.ImageGetter() {
@Override

View File

@ -65,7 +65,7 @@ public class HtmlHelper {
private static final List<String> heads = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "p", "table", "ol", "ul", "br", "hr");
private static final List<String> tails = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "p", "ol", "ul", "li");
static String sanitize(String html, boolean showQuotes) {
static String sanitize(Context context, String html, boolean showQuotes) {
final Document document = Jsoup.parse(Jsoup.clean(html, Whitelist
.relaxed()
.addTags("hr")
@ -137,9 +137,14 @@ public class HtmlHelper {
// Images
for (Element img : document.select("img")) {
String src = img.attr("src");
String alt = img.attr("alt");
String height = img.attr("height").trim();
String width = img.attr("width").trim();
Element div = document.createElement("div");
Uri uri = Uri.parse(img.attr("src"));
Uri uri = Uri.parse(src);
if ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())) {
boolean linked = false;
for (Element parent : img.parents())
@ -160,12 +165,17 @@ public class HtmlHelper {
}
}
String alt = img.attr("alt");
if (!TextUtils.isEmpty(alt)) {
div.appendElement("br");
div.appendElement("em").text(alt);
}
// Tracking image
if ("1".equals(height) && "1".equals(width) && !TextUtils.isEmpty(src)) {
div.appendElement("br");
div.appendElement("strong").text(context.getString(R.string.title_hint_tracking_image));
}
img.replaceWith(div);
}

View File

@ -519,6 +519,7 @@
<string name="title_hint_message_actions">Swipe left to trash; swipe right to archive (if available)</string>
<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_tracking_image">Tracking image</string>
<string name="title_open_link">Open link</string>
<string name="title_show_organization">Show organization</string>