Debug: preview hidden/quotes

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

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

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

@ -1198,7 +1198,7 @@ public class EntityRule {
File file = reply.getFile(context); File file = reply.getFile(context);
Helper.writeText(file, body); Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body, true); String text = HtmlHelper.getFullText(context, body);
reply.preview = HtmlHelper.getPreview(text); reply.preview = HtmlHelper.getPreview(text);
reply.language = HtmlHelper.getLanguage(context, reply.subject, text); reply.language = HtmlHelper.getLanguage(context, reply.subject, text);
db.message().setMessageContent(reply.id, db.message().setMessageContent(reply.id,
@ -1314,7 +1314,7 @@ public class EntityRule {
.append(' ').append(message.subject).append(". "); .append(' ').append(message.subject).append(". ");
String body = Helper.readText(message.getFile(context)); String body = Helper.readText(message.getFile(context));
String text = HtmlHelper.getFullText(body, false); String text = HtmlHelper.getFullText(context, body);
String preview = HtmlHelper.getPreview(text); String preview = HtmlHelper.getPreview(text);
if (!TextUtils.isEmpty(preview)) 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), html);
Helper.writeText(data.draft.getFile(context, data.draft.revision), 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.preview = HtmlHelper.getPreview(text);
data.draft.language = HtmlHelper.getLanguage(context, data.draft.subject, text); data.draft.language = HtmlHelper.getLanguage(context, data.draft.subject, text);
db.message().setMessageContent(data.draft.id, db.message().setMessageContent(data.draft.id,
@ -6369,7 +6369,7 @@ public class FragmentCompose extends FragmentBase {
Helper.writeText(file, html); Helper.writeText(file, html);
Helper.writeText(data.draft.getFile(context, data.draft.revision), 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.preview = HtmlHelper.getPreview(text);
data.draft.language = HtmlHelper.getLanguage(context, data.draft.subject, text); data.draft.language = HtmlHelper.getLanguage(context, data.draft.subject, text);
db.message().setMessageContent(data.draft.id, db.message().setMessageContent(data.draft.id,
@ -7236,7 +7236,7 @@ public class FragmentCompose extends FragmentBase {
if (f.length() > MAX_REASONABLE_SIZE) if (f.length() > MAX_REASONABLE_SIZE)
args.putBoolean("large", true); args.putBoolean("large", true);
String full = HtmlHelper.getFullText(body, true); String full = HtmlHelper.getFullText(context, body);
draft.preview = HtmlHelper.getPreview(full); draft.preview = HtmlHelper.getPreview(full);
draft.language = HtmlHelper.getLanguage(context, draft.subject, full); draft.language = HtmlHelper.getLanguage(context, draft.subject, full);
db.message().setMessageContent(draft.id, db.message().setMessageContent(draft.id,

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

@ -9467,7 +9467,7 @@ public class FragmentMessages extends FragmentBase
Helper.writeText(message.getFile(context), html); Helper.writeText(message.getFile(context), html);
Log.i("pgp html=" + (html == null ? null : html.length())); 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.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text); message.language = HtmlHelper.getLanguage(context, message.subject, text);
@ -10205,7 +10205,7 @@ public class FragmentMessages extends FragmentBase
Helper.writeText(message.getFile(context), html); Helper.writeText(message.getFile(context), html);
Log.i("s/mime html=" + (html == null ? null : html.length())); 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.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, 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 swStrictAlignment;
private SwitchCompat swWebp; private SwitchCompat swWebp;
private SwitchCompat swAnimate; private SwitchCompat swAnimate;
private SwitchCompat swPreviewHidden;
private SwitchCompat swPreviewQuotes;
private SwitchCompat swEasyCorrect; private SwitchCompat swEasyCorrect;
private SwitchCompat swPastePlain; private SwitchCompat swPastePlain;
private EditText etFaviconUri; private EditText etFaviconUri;
@ -305,6 +307,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"exact_alarms", "exact_alarms",
"native_dkim", "native_arc", "native_arc_whitelist", "strict_alignment", "native_dkim", "native_arc", "native_arc_whitelist", "strict_alignment",
"webp", "animate_images", "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", "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", "app_chooser", "app_chooser_share", "share_task",
"adjacent_links", "adjacent_documents", "adjacent_portrait", "adjacent_landscape", "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); swStrictAlignment = view.findViewById(R.id.swStrictAlignment);
swWebp = view.findViewById(R.id.swWebp); swWebp = view.findViewById(R.id.swWebp);
swAnimate = view.findViewById(R.id.swAnimate); swAnimate = view.findViewById(R.id.swAnimate);
swPreviewHidden = view.findViewById(R.id.swPreviewHidden);
swPreviewQuotes = view.findViewById(R.id.swPreviewQuotes);
swEasyCorrect = view.findViewById(R.id.swEasyCorrect); swEasyCorrect = view.findViewById(R.id.swEasyCorrect);
swPastePlain = view.findViewById(R.id.swPastePlain); swPastePlain = view.findViewById(R.id.swPastePlain);
etFaviconUri = view.findViewById(R.id.etFaviconUri); 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() { swEasyCorrect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { 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)); swStrictAlignment.setChecked(prefs.getBoolean("strict_alignment", false));
swWebp.setChecked(prefs.getBoolean("webp", true)); swWebp.setChecked(prefs.getBoolean("webp", true));
swAnimate.setChecked(prefs.getBoolean("animate_images", 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)); swEasyCorrect.setChecked(prefs.getBoolean("easy_correct", false));
swPastePlain.setChecked(prefs.getBoolean("paste_plain", false)); swPastePlain.setChecked(prefs.getBoolean("paste_plain", false));
etFaviconUri.setText(prefs.getString("favicon_uri", null)); etFaviconUri.setText(prefs.getString("favicon_uri", null));

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

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

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

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

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

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

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

@ -1697,6 +1697,30 @@
app:layout_constraintTop_toBottomOf="@id/swWebp" app:layout_constraintTop_toBottomOf="@id/swWebp"
app:switchPadding="12dp" /> 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 <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swEasyCorrect" android:id="@+id/swEasyCorrect"
android:layout_width="0dp" android:layout_width="0dp"
@ -1705,7 +1729,7 @@
android:text="@string/title_advanced_easy_correct" android:text="@string/title_advanced_easy_correct"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAnimate" app:layout_constraintTop_toBottomOf="@id/swPreviewQuotes"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat

@ -989,6 +989,8 @@
<string name="title_advanced_strict_alignment" translatable="false">Strict alignment</string> <string name="title_advanced_strict_alignment" translatable="false">Strict alignment</string>
<string name="title_advanced_webp" translatable="false">WebP</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_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_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_paste_plain" translatable="false">Add paste as plain text</string>
<string name="title_advanced_favicon_uri" translatable="false">Favicon alternative URI</string> <string name="title_advanced_favicon_uri" translatable="false">Favicon alternative URI</string>

Loading…
Cancel
Save