diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index d77027d736..8534ae6505 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -160,7 +160,7 @@ public interface DaoMessage { @Query("SELECT id FROM message" + " WHERE content" + - " AND preview IS NULL") + " AND (preview IS NULL OR preview = '')") List getMessageWithoutPreview(); @Query("SELECT message.*" + @@ -225,8 +225,8 @@ public interface DaoMessage { @Query("UPDATE message SET error = :error WHERE id = :id") int setMessageError(long id, String error); - @Query("UPDATE message SET content = NOT preview IS NULL, preview = :preview WHERE id = :id") - int setMessageContent(long id, String preview); + @Query("UPDATE message SET content = :content, preview = :preview WHERE id = :id") + int setMessageContent(long id, boolean content, String preview); @Query("UPDATE message SET headers = :headers WHERE id = :id") int setMessageHeaders(long id, String headers); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 5c7bdf1449..f68732a3bb 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -134,12 +134,12 @@ public class FragmentOptions extends FragmentEx { try { Log.i(Helper.TAG, "Building preview id=" + id); String html = message.read(context); - String text = Jsoup.parse(html).text(); - String preview = text.substring(0, Math.min(text.length(), 250)); - db.message().setMessageContent(message.id, preview); + String text = (html == null ? null : Jsoup.parse(html).text()); + String preview = (text == null ? null : text.substring(0, Math.min(text.length(), 250))); + db.message().setMessageContent(message.id, true, preview); } catch (IOException ex) { Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); - db.message().setMessageContent(message.id, null); + db.message().setMessageContent(message.id, false, null); if (!metered) EntityOperation.queue(db, message, EntityOperation.BODY); } diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index a9a8c692cf..9d69f9cb18 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -1435,10 +1435,10 @@ public class ServiceSynchronize extends LifecycleService { MessageHelper helper = new MessageHelper((MimeMessage) imessage); String html = helper.getHtml(); - String text = (html == null ? "" : Jsoup.parse(html).text()); - String preview = text.substring(0, Math.min(text.length(), PREVIEW_SIZE)); + String text = (html == null ? null : Jsoup.parse(html).text()); + String preview = (text == null ? null : text.substring(0, Math.min(text.length(), PREVIEW_SIZE))); message.write(this, html); - db.message().setMessageContent(message.id, preview); + db.message().setMessageContent(message.id, true, preview); } private void doAttachment(EntityFolder folder, EntityOperation op, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws JSONException, MessagingException, IOException { @@ -1896,10 +1896,10 @@ public class ServiceSynchronize extends LifecycleService { if (!message.content) if (!metered || (message.size != null && message.size < download)) { String html = helper.getHtml(); - String text = (html == null ? "" : Jsoup.parse(html).text()); - String preview = text.substring(0, Math.min(text.length(), PREVIEW_SIZE)); + String text = (html == null ? null : Jsoup.parse(html).text()); + String preview = (text == null ? null : text.substring(0, Math.min(text.length(), PREVIEW_SIZE))); message.write(context, html); - db.message().setMessageContent(message.id, preview); + db.message().setMessageContent(message.id, true, preview); Log.i(Helper.TAG, folder.name + " downloaded message id=" + message.id + " size=" + message.size); }