Browse Source

Made removing HTML formatting an advanced option

Default off
main
M66B 6 years ago
parent
commit
6fafbaac5a
5 changed files with 51 additions and 9 deletions
  1. +7
    -1
      app/src/main/java/eu/faircode/email/FragmentMessage.java
  2. +10
    -0
      app/src/main/java/eu/faircode/email/FragmentOptions.java
  3. +16
    -3
      app/src/main/java/eu/faircode/email/HtmlHelper.java
  4. +16
    -4
      app/src/main/res/layout/fragment_options.xml
  5. +2
    -1
      app/src/main/res/values/strings.xml

+ 7
- 1
app/src/main/java/eu/faircode/email/FragmentMessage.java View File

@ -224,6 +224,11 @@ public class FragmentMessage extends FragmentEx {
String url = link[0].getURL();
Uri uri = Uri.parse(url);
if (!"http".equals(uri.getScheme()) && !"https".equals(uri.getScheme())) {
Toast.makeText(getContext(), getString(R.string.title_no_viewer, uri.toString()), Toast.LENGTH_LONG).show();
return true;
}
if (BuildConfig.APPLICATION_ID.equals(uri.getHost()) && "/activate/".equals(uri.getPath())) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(
@ -249,6 +254,7 @@ public class FragmentMessage extends FragmentEx {
customTabsIntent.launchUrl(getContext(), Uri.parse(url));
}
}
return true;
}
});
@ -490,7 +496,7 @@ public class FragmentMessage extends FragmentEx {
}, new Html.TagHandler() {
@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
// Do nothing
Log.i(Helper.TAG, "HTML tag=" + tag + " opening=" + opening);
}
});
}


+ 10
- 0
app/src/main/java/eu/faircode/email/FragmentOptions.java View File

@ -36,6 +36,7 @@ import androidx.annotation.Nullable;
public class FragmentOptions extends FragmentEx {
private CheckBox cbWebView;
private TextView tvCustomTabs;
private CheckBox cbSanitize;
private CheckBox cbDebug;
@Override
@ -48,6 +49,7 @@ public class FragmentOptions extends FragmentEx {
// Get controls
cbWebView = view.findViewById(R.id.cbWebView);
tvCustomTabs = view.findViewById(R.id.tvCustomTabs);
cbSanitize = view.findViewById(R.id.cbSanitize);
cbDebug = view.findViewById(R.id.cbDebug);
// Wire controls
@ -62,6 +64,14 @@ public class FragmentOptions extends FragmentEx {
}
});
cbSanitize.setChecked(prefs.getBoolean("sanitize", false));
cbSanitize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sanitize", checked).apply();
}
});
cbDebug.setChecked(prefs.getBoolean("debug", false));
cbDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override


+ 16
- 3
app/src/main/java/eu/faircode/email/HtmlHelper.java View File

@ -20,12 +20,15 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.Html;
import android.text.TextUtils;
import org.jsoup.Jsoup;
import org.jsoup.helper.StringUtil;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.NodeTraversor;
@ -110,9 +113,19 @@ public class HtmlHelper implements NodeVisitor {
}
public static String sanitize(Context context, String html, boolean reply) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Document document = Jsoup.parse(html);
HtmlHelper visitor = new HtmlHelper(context, reply);
NodeTraversor.traverse(visitor, document.body());
return visitor.toString();
if (prefs.getBoolean("sanitize", false)) {
HtmlHelper visitor = new HtmlHelper(context, reply);
NodeTraversor.traverse(visitor, document.body());
return visitor.toString();
} else {
document.getElementsByTag("style").remove();
document.select("[style]").removeAttr("style");
for (Element tr : document.select("tr"))
tr.after("<br>");
return document.body().html();
}
}
}

+ 16
- 4
app/src/main/res/layout/fragment_options.xml View File

@ -18,7 +18,7 @@
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_webview"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorSecondary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -27,12 +27,24 @@
android:id="@+id/tvCustomTabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginStart="45dp"
android:text="@string/title_advanced_customtabs"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbWebView" />
<CheckBox
android:id="@+id/cbSanitize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_sanitize"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorSecondary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCustomTabs" />
<CheckBox
android:id="@+id/cbDebug"
android:layout_width="wrap_content"
@ -40,9 +52,9 @@
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_debug"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorSecondary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCustomTabs" />
app:layout_constraintTop_toBottomOf="@id/cbSanitize" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

+ 2
- 1
app/src/main/res/values/strings.xml View File

@ -66,8 +66,9 @@
<string name="title_setup_dark_theme">Dark theme</string>
<string name="title_advanced">Advanced options</string>
<string name="title_advanced_webview">Use WebView</string>
<string name="title_advanced_webview">Use WebView to show external links</string>
<string name="title_advanced_customtabs">Instead of <a href="https://developer.chrome.com/multidevice/android/customtabs">Chrome Custom Tabs</a></string>
<string name="title_advanced_sanitize">Remove HTML formatting from messages</string>
<string name="title_advanced_debug">Debug</string>
<string name="title_select">Select &#8230;</string>


Loading…
Cancel
Save