Added setting to parse classes

pull/178/head
M66B 5 years ago
parent 8a868b1919
commit a5385d4596

@ -111,6 +111,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
private SwitchCompat swImagesInline; private SwitchCompat swImagesInline;
private SwitchCompat swAttachmentsAlt; private SwitchCompat swAttachmentsAlt;
private SwitchCompat swParseClasses;
private SwitchCompat swAuthentication; private SwitchCompat swAuthentication;
private final static String[] RESET_OPTIONS = new String[]{ private final static String[] RESET_OPTIONS = new String[]{
@ -125,7 +126,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
"addresses", "button_archive_trash", "button_move", "addresses", "button_archive_trash", "button_move",
"contrast", "monospaced", "text_color", "text_size", "contrast", "monospaced", "text_color", "text_size",
"inline_images", "collapse_quotes", "attachments_alt", "inline_images", "collapse_quotes", "attachments_alt",
"authentication" "parse_classes", "authentication"
}; };
@Override @Override
@ -191,6 +192,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swCollapseQuotes = view.findViewById(R.id.swCollapseQuotes); swCollapseQuotes = view.findViewById(R.id.swCollapseQuotes);
swImagesInline = view.findViewById(R.id.swImagesInline); swImagesInline = view.findViewById(R.id.swImagesInline);
swAttachmentsAlt = view.findViewById(R.id.swAttachmentsAlt); swAttachmentsAlt = view.findViewById(R.id.swAttachmentsAlt);
swParseClasses = view.findViewById(R.id.swParseClasses);
swAuthentication = view.findViewById(R.id.swAuthentication); swAuthentication = view.findViewById(R.id.swAuthentication);
setOptions(); setOptions();
@ -621,6 +623,13 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
} }
}); });
swParseClasses.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("parse_classes", checked).apply();
}
});
swAuthentication.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swAuthentication.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -771,6 +780,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swImagesInline.setChecked(prefs.getBoolean("inline_images", false)); swImagesInline.setChecked(prefs.getBoolean("inline_images", false));
swAttachmentsAlt.setChecked(prefs.getBoolean("attachments_alt", false)); swAttachmentsAlt.setChecked(prefs.getBoolean("attachments_alt", false));
swParseClasses.setChecked(prefs.getBoolean("parse_classes", false));
swAuthentication.setChecked(prefs.getBoolean("authentication", true)); swAuthentication.setChecked(prefs.getBoolean("authentication", true));
updateColor(); updateColor();

@ -296,6 +296,7 @@ public class HtmlHelper {
boolean text_size = prefs.getBoolean("text_size", true); boolean text_size = prefs.getBoolean("text_size", true);
boolean display_hidden = prefs.getBoolean("display_hidden", false); boolean display_hidden = prefs.getBoolean("display_hidden", false);
boolean disable_tracking = prefs.getBoolean("disable_tracking", true); boolean disable_tracking = prefs.getBoolean("disable_tracking", true);
boolean parse_classes = prefs.getBoolean("parse_classes", false);
// https://chromium.googlesource.com/chromium/blink/+/master/Source/core/css/html.css // https://chromium.googlesource.com/chromium/blink/+/master/Source/core/css/html.css
@ -378,41 +379,42 @@ public class HtmlHelper {
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style
List<CSSStyleSheet> sheets = new ArrayList<>(); List<CSSStyleSheet> sheets = new ArrayList<>();
for (Element style : parsed.head().select("style")) { if (parse_classes)
if (BuildConfig.DEBUG) for (Element style : parsed.head().select("style")) {
Log.i("Style=" + style.data()); if (BuildConfig.DEBUG)
try { Log.i("Style=" + style.data());
InputSource source = new InputSource(new StringReader(style.data())); try {
String media = style.attr("media"); InputSource source = new InputSource(new StringReader(style.data()));
if (!TextUtils.isEmpty(media)) String media = style.attr("media");
source.setMedia(media); if (!TextUtils.isEmpty(media))
source.setMedia(media);
CSSOMParser parser = new CSSOMParser(new SACParserCSS3());
parser.setErrorHandler(new ErrorHandler() { CSSOMParser parser = new CSSOMParser(new SACParserCSS3());
@Override parser.setErrorHandler(new ErrorHandler() {
public void warning(CSSParseException ex) throws CSSException { @Override
Log.i("CSS warning=" + ex.getMessage()); public void warning(CSSParseException ex) throws CSSException {
} Log.i("CSS warning=" + ex.getMessage());
}
@Override @Override
public void error(CSSParseException ex) throws CSSException { public void error(CSSParseException ex) throws CSSException {
Log.i("CSS error=" + ex.getMessage()); Log.i("CSS error=" + ex.getMessage());
} }
@Override @Override
public void fatalError(CSSParseException ex) throws CSSException { public void fatalError(CSSParseException ex) throws CSSException {
Log.w(ex); Log.w(ex);
} }
}); });
long start = new Date().getTime(); long start = new Date().getTime();
sheets.add(parser.parseStyleSheet(source, null, null)); sheets.add(parser.parseStyleSheet(source, null, null));
long elapsed = new Date().getTime() - start; long elapsed = new Date().getTime() - start;
Log.i("Style parse=" + elapsed + " ms"); Log.i("Style parse=" + elapsed + " ms");
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.w(ex);
}
} }
}
Whitelist whitelist = Whitelist.relaxed() Whitelist whitelist = Whitelist.relaxed()
.addTags("hr", "abbr", "big", "font", "dfn", "del", "s", "tt") .addTags("hr", "abbr", "big", "font", "dfn", "del", "s", "tt")

@ -883,6 +883,29 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAttachmentsAlt" /> app:layout_constraintTop_toBottomOf="@id/swAttachmentsAlt" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swParseClasses"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_parse_classes"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAdvanced"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvParseClassesHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_parse_classes_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swParseClasses" />
<ImageView <ImageView
android:id="@+id/ivAuth" android:id="@+id/ivAuth"
android:layout_width="21dp" android:layout_width="21dp"
@ -904,7 +927,7 @@
android:text="@string/title_advanced_authentication" android:text="@string/title_advanced_authentication"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ivAuth" app:layout_constraintStart_toEndOf="@id/ivAuth"
app:layout_constraintTop_toBottomOf="@id/tvAdvanced" app:layout_constraintTop_toBottomOf="@id/tvParseClassesHint"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx> </eu.faircode.email.ScrollViewEx>

@ -328,7 +328,6 @@
<string name="title_advanced_name_email">Show names and email addresses</string> <string name="title_advanced_name_email">Show names and email addresses</string>
<string name="title_advanced_replace_name">Prefer a contact name over a sent name</string> <string name="title_advanced_replace_name">Prefer a contact name over a sent name</string>
<string name="title_advanced_distinguish_contacts">Underline the sender when the sender is known as local \'to\' contact</string> <string name="title_advanced_distinguish_contacts">Underline the sender when the sender is known as local \'to\' contact</string>
<string name="title_advanced_authentication">Show a warning when the receiving server could not authenticate the message</string>
<string name="title_advanced_font_size_sender">Font size sender</string> <string name="title_advanced_font_size_sender">Font size sender</string>
<string name="title_advanced_font_size_subject">Font size subject</string> <string name="title_advanced_font_size_subject">Font size subject</string>
<string name="title_advanced_subject_top">Show subject above sender</string> <string name="title_advanced_subject_top">Show subject above sender</string>
@ -354,6 +353,8 @@
<string name="title_advanced_actionbar">Show conversation action bar</string> <string name="title_advanced_actionbar">Show conversation action bar</string>
<string name="title_advanced_actionbar_color">Use account color as background color for conversation action bar</string> <string name="title_advanced_actionbar_color">Use account color as background color for conversation action bar</string>
<string name="title_advanced_navbar_colorize">Colorize the Android navigation bar</string> <string name="title_advanced_navbar_colorize">Colorize the Android navigation bar</string>
<string name="title_advanced_parse_classes">Parse style sheets</string>
<string name="title_advanced_authentication">Show a warning when the receiving server could not authenticate the message</string>
<string name="title_advanced_double_back">Double \'back\' to exit</string> <string name="title_advanced_double_back">Double \'back\' to exit</string>
<string name="title_advanced_pull_refresh">Pull down to refresh</string> <string name="title_advanced_pull_refresh">Pull down to refresh</string>
@ -494,6 +495,7 @@
<string name="title_advanced_preview_hint">Only available when message text has been downloaded</string> <string name="title_advanced_preview_hint">Only available when message text has been downloaded</string>
<string name="title_advanced_preview_issue">Scrolling can be slow due to a bug in some Android versions when the number of lines is more than one</string> <string name="title_advanced_preview_issue">Scrolling can be slow due to a bug in some Android versions when the number of lines is more than one</string>
<string name="title_advanced_inline_hint">Inline images are images included in the message</string> <string name="title_advanced_inline_hint">Inline images are images included in the message</string>
<string name="title_advanced_parse_classes_hint">This will more accurately display messages, but possibly with a delay</string>
<string name="title_advanced_autoexpand_hint">Automatically open message when there is just one message or just one unread message in a conversation</string> <string name="title_advanced_autoexpand_hint">Automatically open message when there is just one message or just one unread message in a conversation</string>
<string name="title_advanced_autoseen_hint">Automatically marking messages read on expanding can be disabled in the individual account settings</string> <string name="title_advanced_autoseen_hint">Automatically marking messages read on expanding can be disabled in the individual account settings</string>

Loading…
Cancel
Save