Debug: preview hidden/quotes

pull/216/head
M66B 3 months ago
parent 9386f13807
commit 1564a93338

@ -885,7 +885,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
if (criteria.in_message) {
// This won't match <p>An <b>example</b><p> when searching for "An example"
if (contains(html, criteria.query, partial, true)) {
String text = HtmlHelper.getFullText(html, false);
String text = HtmlHelper.getFullText(context, html);
if (contains(text, criteria.query, partial, false))
return true;
}

@ -2144,7 +2144,7 @@ class Core {
String body = parts.getHtml(context, plain_text, charset);
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body, true);
String text = HtmlHelper.getFullText(context, body);
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);
Integer plain_only = parts.isPlainOnly();
@ -2324,7 +2324,7 @@ class Core {
String body = parts.getHtml(context, plain_text, charset);
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body, true);
String text = HtmlHelper.getFullText(context, body);
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);
Integer plain_only = parts.isPlainOnly();
@ -3686,7 +3686,7 @@ class Core {
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body, true);
String text = HtmlHelper.getFullText(context, body);
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);
db.message().setMessageContent(message.id,
@ -4991,7 +4991,7 @@ class Core {
body = parts.getHtml(context, download_plain);
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body, true);
String text = HtmlHelper.getFullText(context, body);
message.content = true;
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);
@ -5511,7 +5511,7 @@ class Core {
String body = parts.getHtml(context);
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body, true);
String text = HtmlHelper.getFullText(context, body);
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);
db.message().setMessageContent(message.id,

@ -1198,7 +1198,7 @@ public class EntityRule {
File file = reply.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body, true);
String text = HtmlHelper.getFullText(context, body);
reply.preview = HtmlHelper.getPreview(text);
reply.language = HtmlHelper.getLanguage(context, reply.subject, text);
db.message().setMessageContent(reply.id,
@ -1314,7 +1314,7 @@ public class EntityRule {
.append(' ').append(message.subject).append(". ");
String body = Helper.readText(message.getFile(context));
String text = HtmlHelper.getFullText(body, false);
String text = HtmlHelper.getFullText(context, body);
String preview = HtmlHelper.getPreview(text);
if (!TextUtils.isEmpty(preview))

@ -6179,7 +6179,7 @@ public class FragmentCompose extends FragmentBase {
Helper.writeText(data.draft.getFile(context), html);
Helper.writeText(data.draft.getFile(context, data.draft.revision), html);
String text = HtmlHelper.getFullText(html, true);
String text = HtmlHelper.getFullText(context, html);
data.draft.preview = HtmlHelper.getPreview(text);
data.draft.language = HtmlHelper.getLanguage(context, data.draft.subject, text);
db.message().setMessageContent(data.draft.id,
@ -6369,7 +6369,7 @@ public class FragmentCompose extends FragmentBase {
Helper.writeText(file, html);
Helper.writeText(data.draft.getFile(context, data.draft.revision), html);
String text = HtmlHelper.getFullText(html, true);
String text = HtmlHelper.getFullText(context, html);
data.draft.preview = HtmlHelper.getPreview(text);
data.draft.language = HtmlHelper.getLanguage(context, data.draft.subject, text);
db.message().setMessageContent(data.draft.id,
@ -7236,7 +7236,7 @@ public class FragmentCompose extends FragmentBase {
if (f.length() > MAX_REASONABLE_SIZE)
args.putBoolean("large", true);
String full = HtmlHelper.getFullText(body, true);
String full = HtmlHelper.getFullText(context, body);
draft.preview = HtmlHelper.getPreview(full);
draft.language = HtmlHelper.getLanguage(context, draft.subject, full);
db.message().setMessageContent(draft.id,

@ -1650,7 +1650,7 @@ public class FragmentFolders extends FragmentBase {
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body, true);
String text = HtmlHelper.getFullText(context, body);
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);
db.message().setMessageContent(message.id,

@ -9467,7 +9467,7 @@ public class FragmentMessages extends FragmentBase
Helper.writeText(message.getFile(context), html);
Log.i("pgp html=" + (html == null ? null : html.length()));
String text = HtmlHelper.getFullText(html, true);
String text = HtmlHelper.getFullText(context, html);
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);
@ -10205,7 +10205,7 @@ public class FragmentMessages extends FragmentBase
Helper.writeText(message.getFile(context), html);
Log.i("s/mime html=" + (html == null ? null : html.length()));
String text = HtmlHelper.getFullText(html, true);
String text = HtmlHelper.getFullText(context, html);
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);

@ -225,6 +225,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swStrictAlignment;
private SwitchCompat swWebp;
private SwitchCompat swAnimate;
private SwitchCompat swPreviewHidden;
private SwitchCompat swPreviewQuotes;
private SwitchCompat swEasyCorrect;
private SwitchCompat swPastePlain;
private EditText etFaviconUri;
@ -305,6 +307,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"exact_alarms",
"native_dkim", "native_arc", "native_arc_whitelist", "strict_alignment",
"webp", "animate_images",
"preview_hidden", "preview_quotes",
"easy_correct", "paste_plain", "favicon_uri", "infra", "tld_flags", "json_ld", "dup_msgids", "thread_byref", "save_user_flags", "mdn",
"app_chooser", "app_chooser_share", "share_task",
"adjacent_links", "adjacent_documents", "adjacent_portrait", "adjacent_landscape",
@ -485,6 +488,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swStrictAlignment = view.findViewById(R.id.swStrictAlignment);
swWebp = view.findViewById(R.id.swWebp);
swAnimate = view.findViewById(R.id.swAnimate);
swPreviewHidden = view.findViewById(R.id.swPreviewHidden);
swPreviewQuotes = view.findViewById(R.id.swPreviewQuotes);
swEasyCorrect = view.findViewById(R.id.swEasyCorrect);
swPastePlain = view.findViewById(R.id.swPastePlain);
etFaviconUri = view.findViewById(R.id.etFaviconUri);
@ -1635,6 +1640,20 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
swPreviewHidden.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("preview_hidden", checked).apply();
}
});
swPreviewQuotes.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("preview_quotes", checked).apply();
}
});
swEasyCorrect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -2527,6 +2546,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swStrictAlignment.setChecked(prefs.getBoolean("strict_alignment", false));
swWebp.setChecked(prefs.getBoolean("webp", true));
swAnimate.setChecked(prefs.getBoolean("animate_images", true));
swPreviewHidden.setChecked(prefs.getBoolean("preview_hidden", true));
swPreviewQuotes.setChecked(prefs.getBoolean("preview_quotes", true));
swEasyCorrect.setChecked(prefs.getBoolean("easy_correct", false));
swPastePlain.setChecked(prefs.getBoolean("paste_plain", false));
etFaviconUri.setText(prefs.getString("favicon_uri", null));

@ -2615,31 +2615,35 @@ public class HtmlHelper {
return truncate(preview, PREVIEW_SIZE);
}
static String getFullText(String body, boolean hidden) {
static String getFullText(Context context, String body) {
try {
if (body == null)
return null;
Document d = JsoupEx.parse(body);
return _getText(d, hidden);
return _getText(context, d);
} catch (OutOfMemoryError ex) {
Log.e(ex);
return null;
}
}
static String getFullText(File file, boolean hidden) throws IOException {
static String getFullText(Context context, File file) throws IOException {
try {
Document d = JsoupEx.parse(file);
return _getText(d, hidden);
return _getText(context, d);
} catch (OutOfMemoryError ex) {
Log.e(ex);
return null;
}
}
private static String _getText(Document d, boolean hidden) {
private static String _getText(Context context, Document d) {
truncate(d, MAX_FULL_TEXT_SIZE);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean preview_hidden = prefs.getBoolean("preview_hidden", true);
boolean preview_quotes = prefs.getBoolean("preview_quotes", true);
for (Element e : d.select("*")) {
String style = e.attr("style");
if (TextUtils.isEmpty(style))
@ -2658,13 +2662,19 @@ public class HtmlHelper {
.trim()
.toLowerCase(Locale.ROOT)
.replaceAll("\\s+", " ");
if (!hidden && "display".equals(key) && "none".equals(value)) {
if (!preview_hidden && "display".equals(key) && "none".equals(value)) {
e.remove();
break;
}
}
}
if (!preview_quotes) {
Element top = d.select("blockquote").first();
if (top != null && top.previousElementSibling() == null)
top.remove();
}
for (Element bq : d.select("blockquote"))
bq.prependChild(new TextNode("> "));

@ -177,7 +177,7 @@ public class MessageClassifier {
if (message.subject != null)
texts.add(message.subject);
String text = HtmlHelper.getFullText(file, false);
String text = HtmlHelper.getFullText(context, file);
if (text != null)
texts.add(text);

@ -1012,7 +1012,7 @@ class NotificationHelper {
if (notify_preview_all)
try {
File file = message.getFile(context);
preview = HtmlHelper.getFullText(file, true);
preview = HtmlHelper.getFullText(context, file);
if (preview != null && preview.length() > MAX_PREVIEW)
preview = preview.substring(0, MAX_PREVIEW);
} catch (Throwable ex) {

@ -347,7 +347,7 @@ public class ServiceExternal extends ServiceBase {
File file = msg.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body, true);
String text = HtmlHelper.getFullText(context, body);
msg.preview = HtmlHelper.getPreview(text);
msg.language = HtmlHelper.getLanguage(context, msg.subject, text);
db.message().setMessageContent(msg.id,

@ -733,7 +733,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
if (plain != null && (plain & 1) != 0)
body = body.replace("<div x-plain=\"true\">", "<div>");
String text = HtmlHelper.getFullText(body, true);
String text = HtmlHelper.getFullText(this, body);
String language = HtmlHelper.getLanguage(this, message.subject, text);
String preview = HtmlHelper.getPreview(text);

@ -341,7 +341,7 @@ public class ServiceUI extends IntentService {
Object obj = results.get("text");
String body = (obj == null ? null : "<p>" + obj.toString().replaceAll("\\r?\\n", "<br>") + "</p>");
String text = HtmlHelper.getFullText(body, true);
String text = HtmlHelper.getFullText(this, body);
String language = HtmlHelper.getLanguage(this, ref.subject, text);
String preview = HtmlHelper.getPreview(text);

@ -86,7 +86,7 @@ public class WorkerFts extends Worker {
String text = null;
if (message.content) {
File file = message.getFile(context);
text = HtmlHelper.getFullText(file, false);
text = HtmlHelper.getFullText(context, file);
}
try {

@ -1697,6 +1697,30 @@
app:layout_constraintTop_toBottomOf="@id/swWebp"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPreviewHidden"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_preview_hidden"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAnimate"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPreviewQuotes"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_preview_quotes"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swPreviewHidden"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swEasyCorrect"
android:layout_width="0dp"
@ -1705,7 +1729,7 @@
android:text="@string/title_advanced_easy_correct"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAnimate"
app:layout_constraintTop_toBottomOf="@id/swPreviewQuotes"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

@ -989,6 +989,8 @@
<string name="title_advanced_strict_alignment" translatable="false">Strict alignment</string>
<string name="title_advanced_webp" translatable="false">WebP</string>
<string name="title_advanced_animate" translatable="false">Animate images (GIF, etc.)</string>
<string name="title_advanced_preview_hidden" translatable="false">Preview hidden</string>
<string name="title_advanced_preview_quotes" translatable="false">Preview quotes</string>
<string name="title_advanced_easy_correct" translatable="false">Easy correct</string>
<string name="title_advanced_paste_plain" translatable="false">Add paste as plain text</string>
<string name="title_advanced_favicon_uri" translatable="false">Favicon alternative URI</string>

Loading…
Cancel
Save