Show image description when not showing images

This commit is contained in:
M66B 2019-06-30 09:59:03 +02:00
parent 655f0e3d3b
commit a6963da515
4 changed files with 22 additions and 14 deletions

View File

@ -127,7 +127,7 @@ public class ActivityEml extends ActivityBase {
result.html = parts.getHtml(context); result.html = parts.getHtml(context);
if (result.html != null) if (result.html != null)
result.body = HtmlHelper.fromHtml(HtmlHelper.sanitize(context, result.html)); result.body = HtmlHelper.fromHtml(HtmlHelper.sanitize(context, result.html, false));
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
mmessage.writeTo(bos); mmessage.writeTo(bos);

View File

@ -2054,7 +2054,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
body = document.html(); body = document.html();
} }
String html = HtmlHelper.sanitize(context, body); String html = HtmlHelper.sanitize(context, body, show_images);
if (debug) if (debug)
html += "<pre>" + Html.escapeHtml(html) + "</pre>"; html += "<pre>" + Html.escapeHtml(html) + "</pre>";

View File

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

View File

@ -84,7 +84,7 @@ public class HtmlHelper {
private static final ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory); private static final ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
static String sanitize(Context context, String html) { static String sanitize(Context context, String html, boolean show_images) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean paranoid = prefs.getBoolean("paranoid", true); boolean paranoid = prefs.getBoolean("paranoid", true);
@ -224,17 +224,25 @@ public class HtmlHelper {
else else
table.tagName("div"); table.tagName("div");
// Remove link tracking pixels // Images
if (paranoid) for (Element img : document.select("img")) {
for (Element img : document.select("img")) // Remove link tracking pixels
if (isTrackingPixel(img)) { if (paranoid && isTrackingPixel(img)) {
String src = img.attr("src"); String src = img.attr("src");
img.removeAttr("src"); img.removeAttr("src");
img.tagName("a"); img.tagName("a");
img.attr("href", src); img.attr("href", src);
img.appendText(context.getString(R.string.title_hint_tracking_image, img.appendText(context.getString(R.string.title_hint_tracking_image,
img.attr("width"), img.attr("height"))); img.attr("width"), img.attr("height")));
}
if (!show_images) {
String alt = img.attr("alt");
if (!TextUtils.isEmpty(alt)) {
img.appendText(alt);
} }
}
}
// Autolink // Autolink
final Pattern pattern = Pattern.compile( final Pattern pattern = Pattern.compile(