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

@ -2076,7 +2076,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);
String text = HtmlHelper.getFullText(body, true);
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);
Integer plain_only = parts.isPlainOnly();
@ -2249,7 +2249,7 @@ class Core {
String body = parts.getHtml(context, download_plain);
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body);
String text = HtmlHelper.getFullText(body, true);
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);
@ -3611,7 +3611,7 @@ class Core {
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body);
String text = HtmlHelper.getFullText(body, true);
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);
db.message().setMessageContent(message.id,
@ -4898,7 +4898,7 @@ class Core {
body = parts.getHtml(context, download_plain);
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body);
String text = HtmlHelper.getFullText(body, true);
message.content = true;
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);
@ -5418,7 +5418,7 @@ class Core {
String body = parts.getHtml(context);
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body);
String text = HtmlHelper.getFullText(body, true);
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);
db.message().setMessageContent(message.id,

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

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

@ -9290,7 +9290,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);
String text = HtmlHelper.getFullText(html, true);
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);
@ -10011,7 +10011,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);
String text = HtmlHelper.getFullText(html, true);
message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text);

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

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

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

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

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

Loading…
Cancel
Save