diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index f79429c835..502bade50a 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -3953,7 +3953,8 @@ class Core { // Delete old local messages long delete_time = new Date().getTime() - 3600 * 1000L; if (auto_delete) { - List tbds = db.message().getMessagesBefore(folder.id, delete_time, keep_time, keep_unread_time, delete_unseen); + List tbds = db.message().getMessagesBefore(folder.id, delete_time, keep_time, + !delete_unseen || sync_unseen ? 0 : keep_unread_time); Log.i(folder.name + " local tbd=" + tbds.size()); EntityFolder trash = db.folder().getFolderByType(folder.account, EntityFolder.TRASH); for (Long tbd : tbds) { @@ -3967,7 +3968,7 @@ class Core { } } else { int old = db.message().deleteMessagesBefore(folder.id, delete_time, keep_time, - sync_unseen ? 0 : keep_unread_time, delete_unseen && !sync_unseen); + !delete_unseen || sync_unseen ? 0 : keep_unread_time); Log.i(folder.name + " local old=" + old); } diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 6447ceb46a..97e3db5b4b 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -1043,21 +1043,21 @@ public interface DaoMessage { " WHERE folder = :folder" + " AND received < :keep_time" + " AND NOT uid IS NULL" + - " AND (ui_seen OR received < :keep_unread_time OR :unseen)" + + " AND (ui_seen OR received < :keep_unread_time)" + " AND NOT ui_flagged" + " AND stored < :sync_time" + // moved, browsed " AND (ui_snoozed IS NULL OR ui_snoozed =" + Long.MAX_VALUE + ")") - List getMessagesBefore(long folder, long sync_time, long keep_time, long keep_unread_time, boolean unseen); + List getMessagesBefore(long folder, long sync_time, long keep_time, long keep_unread_time); @Query("DELETE FROM message" + " WHERE folder = :folder" + " AND received < :keep_time" + " AND NOT uid IS NULL" + - " AND (ui_seen OR received < :keep_unread_time OR :unseen)" + + " AND (ui_seen OR received < :keep_unread_time)" + " AND NOT ui_flagged" + " AND stored < :sync_time" + // moved, browsed " AND (ui_snoozed IS NULL OR ui_snoozed = " + Long.MAX_VALUE + ")") - int deleteMessagesBefore(long folder, long sync_time, long keep_time, long keep_unread_time, boolean unseen); + int deleteMessagesBefore(long folder, long sync_time, long keep_time, long keep_unread_time); @Transaction @Query("DELETE FROM message" +