mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-26 09:47:13 +00:00
Cleanup message & attachment files
This commit is contained in:
parent
3ef26e5e46
commit
ae8eb762f8
3 changed files with 38 additions and 3 deletions
|
@ -34,11 +34,16 @@ public interface DaoAttachment {
|
|||
" ORDER BY sequence")
|
||||
LiveData<List<EntityAttachment>> liveAttachments(long id);
|
||||
|
||||
@Query("SELECT COUNT(attachment.id)" +
|
||||
@Query("SELECT COUNT(id)" +
|
||||
" FROM attachment" +
|
||||
" WHERE message = :message")
|
||||
int getAttachmentCount(long message);
|
||||
|
||||
@Query("SELECT COUNT(id)" +
|
||||
" FROM attachment" +
|
||||
" WHERE id = :id")
|
||||
int countAttachment(long id);
|
||||
|
||||
@Query("SELECT * FROM attachment" +
|
||||
" WHERE message = :message" +
|
||||
" ORDER BY sequence")
|
||||
|
|
|
@ -74,10 +74,20 @@ public interface DaoMessage {
|
|||
" ORDER BY message.received DESC, message.sent DESC")
|
||||
DataSource.Factory<Integer, TupleMessageEx> pagedThread(long msgid, boolean debug);
|
||||
|
||||
@Query("SELECT * FROM message WHERE id = :id")
|
||||
@Query("SELECT *" +
|
||||
" FROM message" +
|
||||
" WHERE id = :id")
|
||||
EntityMessage getMessage(long id);
|
||||
|
||||
@Query("SELECT * FROM message WHERE folder = :folder AND uid = :uid")
|
||||
@Query("SELECT COUNT(id)" +
|
||||
" FROM message" +
|
||||
" WHERE id = :id")
|
||||
int countMessage(long id);
|
||||
|
||||
@Query("SELECT *" +
|
||||
" FROM message" +
|
||||
" WHERE folder = :folder" +
|
||||
" AND uid = :uid")
|
||||
EntityMessage getMessageByUid(long folder, long uid);
|
||||
|
||||
@Query("SELECT message.* FROM message" +
|
||||
|
|
|
@ -1183,6 +1183,26 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
|
||||
}
|
||||
|
||||
// Cleanup files
|
||||
File messages = new File(getFilesDir(), "messages");
|
||||
for (File file : messages.listFiles())
|
||||
if (file.isFile()) {
|
||||
long id = Long.parseLong(file.getName());
|
||||
if (db.message().countMessage(id) == 0) {
|
||||
Log.i(Helper.TAG, "Cleanup message id=" + id);
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
File attachments = new File(getFilesDir(), "attachments");
|
||||
for (File file : attachments.listFiles())
|
||||
if (file.isFile()) {
|
||||
long id = Long.parseLong(file.getName());
|
||||
if (db.attachment().countAttachment(id) == 0) {
|
||||
Log.i(Helper.TAG, "Cleanup attachment id=" + id);
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
Log.w(Helper.TAG, folder.name + " statistics added=" + added + " updated=" + updated + " unchanged=" + unchanged);
|
||||
} finally {
|
||||
Log.v(Helper.TAG, folder.name + " end sync");
|
||||
|
|
Loading…
Reference in a new issue