Use invisible text for preview text

Like Gmail, Outlook and Apple do
pull/215/head
M66B 8 months ago
parent bfa347aa71
commit 12e79ce7e9

@ -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); String text = HtmlHelper.getFullText(html, false);
if (contains(text, criteria.query, partial, false)) if (contains(text, criteria.query, partial, false))
return true; return true;
} }

@ -2076,7 +2076,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); String text = HtmlHelper.getFullText(body, 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);
Integer plain_only = parts.isPlainOnly(); Integer plain_only = parts.isPlainOnly();
@ -2249,7 +2249,7 @@ class Core {
String body = parts.getHtml(context, download_plain); String 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); String text = HtmlHelper.getFullText(body, 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);
@ -3611,7 +3611,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); String text = HtmlHelper.getFullText(body, 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);
db.message().setMessageContent(message.id, db.message().setMessageContent(message.id,
@ -4898,7 +4898,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); String text = HtmlHelper.getFullText(body, true);
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);
@ -5418,7 +5418,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); String text = HtmlHelper.getFullText(body, 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);
db.message().setMessageContent(message.id, db.message().setMessageContent(message.id,

@ -1180,7 +1180,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); String text = HtmlHelper.getFullText(body, true);
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,
@ -1292,7 +1292,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); String text = HtmlHelper.getFullText(body, false);
String preview = HtmlHelper.getPreview(text); String preview = HtmlHelper.getPreview(text);
if (!TextUtils.isEmpty(preview)) if (!TextUtils.isEmpty(preview))

@ -6140,7 +6140,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); String text = HtmlHelper.getFullText(html, true);
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,
@ -6327,7 +6327,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); String text = HtmlHelper.getFullText(html, true);
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,
@ -7194,7 +7194,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); String full = HtmlHelper.getFullText(body, true);
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,

@ -1676,7 +1676,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); String text = HtmlHelper.getFullText(body, 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);
db.message().setMessageContent(message.id, db.message().setMessageContent(message.id,

@ -9290,7 +9290,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); String text = HtmlHelper.getFullText(html, 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);
@ -10011,7 +10011,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); String text = HtmlHelper.getFullText(html, 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);

@ -2624,29 +2624,29 @@ public class HtmlHelper {
return truncate(preview, PREVIEW_SIZE); return truncate(preview, PREVIEW_SIZE);
} }
static String getFullText(String body) { static String getFullText(String body, boolean hidden) {
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); return _getText(d, hidden);
} catch (OutOfMemoryError ex) { } catch (OutOfMemoryError ex) {
Log.e(ex); Log.e(ex);
return null; return null;
} }
} }
static String getFullText(File file) throws IOException { static String getFullText(File file, boolean hidden) throws IOException {
try { try {
Document d = JsoupEx.parse(file); Document d = JsoupEx.parse(file);
return _getText(d); return _getText(d, hidden);
} catch (OutOfMemoryError ex) { } catch (OutOfMemoryError ex) {
Log.e(ex); Log.e(ex);
return null; return null;
} }
} }
private static String _getText(Document d) { private static String _getText(Document d, boolean hidden) {
truncate(d, MAX_FULL_TEXT_SIZE); truncate(d, MAX_FULL_TEXT_SIZE);
for (Element e : d.select("*")) { for (Element e : d.select("*")) {
@ -2667,7 +2667,7 @@ public class HtmlHelper {
.trim() .trim()
.toLowerCase(Locale.ROOT) .toLowerCase(Locale.ROOT)
.replaceAll("\\s+", " "); .replaceAll("\\s+", " ");
if ("display".equals(key) && "none".equals(value)) { if (!hidden && "display".equals(key) && "none".equals(value)) {
e.remove(); e.remove();
break; break;
} }

@ -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); String text = HtmlHelper.getFullText(file, false);
if (text != null) if (text != null)
texts.add(text); texts.add(text);

@ -1003,7 +1003,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); preview = HtmlHelper.getFullText(file, true);
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) {

@ -337,7 +337,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); String text = HtmlHelper.getFullText(body, true);
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,

@ -722,7 +722,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); String text = HtmlHelper.getFullText(body, true);
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); String text = HtmlHelper.getFullText(body, true);
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); text = HtmlHelper.getFullText(file, false);
} }
try { try {

Loading…
Cancel
Save