MCPcopy Create free account
hub / github.com/M66B/FairEmail / sanitize

Method sanitize

app/src/main/java/eu/faircode/email/HtmlHelper.java:468–1522  ·  view source on GitHub ↗
(Context context, Document parsed, boolean view, boolean show_images)

Source from the content-addressed store, hash-verified

466 }
467
468 private static Document sanitize(Context context, Document parsed, boolean view, boolean show_images) {
469 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
470 String theme = prefs.getString("theme", "blue_orange_system");
471 boolean bw = "black_and_white".equals(theme);
472 boolean background_color = (!view || (!bw && prefs.getBoolean("background_color", false)));
473 boolean text_color = (!view || (!bw && prefs.getBoolean("text_color", true)));
474 boolean text_size = (!view || prefs.getBoolean("text_size", true));
475 boolean text_font = (!view || prefs.getBoolean("text_font", true));
476 boolean text_align = prefs.getBoolean("text_align", true);
477 boolean text_titles = prefs.getBoolean("text_titles", false);
478 boolean display_hidden = prefs.getBoolean("display_hidden", false);
479 boolean disable_tracking = prefs.getBoolean("disable_tracking", true);
480 boolean parse_classes = prefs.getBoolean("parse_classes", true);
481 boolean inline_images = prefs.getBoolean("inline_images", false);
482 boolean text_separators = prefs.getBoolean("text_separators", true);
483 boolean image_placeholders = prefs.getBoolean("image_placeholders", true);
484
485 boolean dark = Helper.isDarkTheme(context);
486 int textColorPrimary = Helper.resolveColor(context, android.R.attr.textColorPrimary);
487 int textColorPrimaryInverse = Helper.resolveColor(context, android.R.attr.textColorPrimaryInverse);
488
489 int textSizeSmall;
490 TypedArray ta = context.obtainStyledAttributes(
491 androidx.appcompat.R.style.TextAppearance_AppCompat_Small, new int[]{android.R.attr.textSize});
492 if (ta == null)
493 textSizeSmall = Helper.dp2pixels(context, 6);
494 else {
495 textSizeSmall = ta.getDimensionPixelSize(0, 0);
496 ta.recycle();
497 }
498
499 // https://chromium.googlesource.com/chromium/blink/+/master/Source/core/css/html.css
500
501 // <!--[if ...]><!--> ... <!--<![endif]-->
502 // https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/compatibility/hh801214(v=vs.85)
503 if (!display_hidden && false)
504 parsed.filter(new NodeFilter() {
505 private boolean remove = false;
506
507 @Override
508 public FilterResult head(Node node, int depth) {
509 if (node instanceof Comment) {
510 String data = ((Comment) node).getData().trim();
511 if (data.startsWith("[if") && !data.endsWith("endif]")) {
512 remove = true;
513 return FilterResult.REMOVE;
514 } else if (remove && data.endsWith("endif]")) {
515 remove = false;
516 return FilterResult.REMOVE;
517 }
518 }
519 return (remove ? FilterResult.REMOVE : FilterResult.CONTINUE);
520 }
521
522 @Override
523 public FilterResult tail(Node node, int depth) {
524 return FilterResult.CONTINUE;
525 }

Callers 2

sanitizeComposeMethod · 0.95
sanitizeViewMethod · 0.95

Calls 15

isDarkThemeMethod · 0.95
resolveColorMethod · 0.95
dp2pixelsMethod · 0.95
normalizeNamespacesMethod · 0.95
truncateMethod · 0.95
getMaxFormatTextSizeMethod · 0.95
parseStylesMethod · 0.95
removeTrackingPixelsMethod · 0.95
parseIntMethod · 0.95
iMethod · 0.95
processStylesMethod · 0.95
mergeStylesMethod · 0.95

Tested by

no test coverage detected