mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-30 19:56:10 +00:00
Check message and attachment files on cleanup
This commit is contained in:
parent
83464aafe0
commit
45c01d39a4
3 changed files with 42 additions and 0 deletions
|
@ -63,6 +63,10 @@ public interface DaoAttachment {
|
|||
" LIMIT 1")
|
||||
EntityAttachment getAttachment(long message, String cid);
|
||||
|
||||
@Query("SELECT id FROM attachment" +
|
||||
" WHERE available")
|
||||
List<Long> getAttachmentAvailable();
|
||||
|
||||
@Query("UPDATE attachment" +
|
||||
" SET message = :message" +
|
||||
" WHERE id = :id")
|
||||
|
@ -78,6 +82,11 @@ public interface DaoAttachment {
|
|||
" WHERE id = :id")
|
||||
void setDownloaded(long id, Long size);
|
||||
|
||||
@Query("UPDATE attachment" +
|
||||
" SET size = NULL, progress = NULL, available = 0" +
|
||||
" WHERE id = :id")
|
||||
void setUnavailable(long id);
|
||||
|
||||
@Query("UPDATE attachment" +
|
||||
" SET error = :error, progress = NULL, available = 0" +
|
||||
" WHERE id = :id")
|
||||
|
|
|
@ -216,6 +216,12 @@ public interface DaoMessage {
|
|||
" ORDER BY message.received DESC")
|
||||
List<Long> getMessageAll(Long folder, boolean snoozed);
|
||||
|
||||
@Query("SELECT id" +
|
||||
" FROM message" +
|
||||
" WHERE content" +
|
||||
" ORDER BY message.received DESC")
|
||||
List<Long> getMessageWithContent();
|
||||
|
||||
@Query("SELECT *" +
|
||||
" FROM message" +
|
||||
" WHERE account = :account" +
|
||||
|
@ -380,6 +386,9 @@ public interface DaoMessage {
|
|||
@Query("UPDATE message SET revisions = :revisions WHERE id = :id")
|
||||
int setMessageRevisions(long id, Integer revisions);
|
||||
|
||||
@Query("UPDATE message SET content = :content WHERE id = :id")
|
||||
int setMessageContent(long id, boolean content);
|
||||
|
||||
@Query("UPDATE message SET content = :content, plain_only = :plain_only, preview = :preview, warning = :warning WHERE id = :id")
|
||||
int setMessageContent(long id, boolean content, Boolean plain_only, String preview, String warning);
|
||||
|
||||
|
|
|
@ -135,6 +135,30 @@ public class WorkerCleanup extends Worker {
|
|||
Log.w("Error deleting " + file);
|
||||
}
|
||||
|
||||
// Check message files
|
||||
Log.i("Checking message files");
|
||||
List<Long> mids = db.message().getMessageWithContent();
|
||||
for (Long mid : mids) {
|
||||
EntityMessage message = db.message().getMessage(mid);
|
||||
File file = message.getFile(context);
|
||||
if (!file.exists()) {
|
||||
Log.w("Message file missing id=" + mid);
|
||||
db.message().setMessageContent(mid, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Check attachments files
|
||||
Log.i("Checking attachments files");
|
||||
List<Long> aids = db.attachment().getAttachmentAvailable();
|
||||
for (Long aid : aids) {
|
||||
EntityAttachment attachment = db.attachment().getAttachment(aid);
|
||||
File file = attachment.getFile(context);
|
||||
if (!file.exists()) {
|
||||
Log.w("Attachment file missing id=" + aid);
|
||||
db.attachment().setUnavailable(aid);
|
||||
}
|
||||
}
|
||||
|
||||
Log.i("Cleanup contacts");
|
||||
int contacts = db.contact().deleteContacts(now - KEEP_CONTACTS_DURATION);
|
||||
Log.i("Deleted contacts=" + contacts);
|
||||
|
|
Loading…
Reference in a new issue