diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 3d0a0314b7..3bf93e54f0 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1457,9 +1457,38 @@ class Core { } catch (Throwable ex) { Log.e(ex); } + + updateMessageSize(context, message.id); } } + private static void updateMessageSize(Context context, long id) { + DB db = DB.getInstance(context); + + EntityMessage message = db.message().getMessage(id); + if (message == null || !message.content) + return; + + int size = (int) message.getFile(context).length(); + if (size == 0) + return; + + List attachments = db.attachment().getAttachments(message.id); + for (EntityAttachment attachment : attachments) { + if (!attachment.available) + return; + + long asize = attachment.getFile(context).length(); + if (asize == 0) + return; + + size += asize; + } + + Log.i("Setting message=" + id + " size=" + message.size + "/" + size); + db.message().setMessageSize(message.id, size); + } + static void notifyMessages(Context context, List messages) { Log.i("Notify messages=" + messages.size()); diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 891c0044f7..6f4100cf96 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -324,6 +324,9 @@ public interface DaoMessage { @Query("UPDATE message SET content = :content, preview = :preview, warning = :warning WHERE id = :id") int setMessageContent(long id, boolean content, String preview, String warning); + @Query("UPDATE message SET size = :size WHERE id = :id") + int setMessageSize(long id, Integer size); + @Query("UPDATE message SET headers = :headers WHERE id = :id") int setMessageHeaders(long id, String headers);