mirror of https://github.com/M66B/FairEmail.git
Added daily folder cleanup
This commit is contained in:
parent
3dabbbb677
commit
9d6a8b1c06
|
@ -82,6 +82,9 @@ public interface DaoFolder {
|
|||
" WHERE folder.id = :id")
|
||||
LiveData<TupleFolderEx> liveFolderEx(long id);
|
||||
|
||||
@Query("SELECT * FROM folder ORDER BY account, name")
|
||||
List<EntityFolder> getFolders();
|
||||
|
||||
@Query("SELECT * FROM folder WHERE id = :id")
|
||||
EntityFolder getFolder(Long id);
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import android.content.Context;
|
|||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
@ -66,6 +67,25 @@ public class JobDaily extends JobService {
|
|||
|
||||
Log.i(Helper.TAG, "Start daily job");
|
||||
|
||||
// Cleanup folders
|
||||
Log.i(Helper.TAG, "Cleanup folders");
|
||||
for (EntityFolder folder : db.folder().getFolders()) {
|
||||
Calendar cal_keep = Calendar.getInstance();
|
||||
cal_keep.add(Calendar.DAY_OF_MONTH, -folder.keep_days);
|
||||
cal_keep.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal_keep.set(Calendar.MINUTE, 0);
|
||||
cal_keep.set(Calendar.SECOND, 0);
|
||||
cal_keep.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
long keep_time = cal_keep.getTimeInMillis();
|
||||
if (keep_time < 0)
|
||||
keep_time = 0;
|
||||
|
||||
int messages = db.message().deleteMessagesBefore(folder.id, keep_time, false);
|
||||
Log.i(Helper.TAG, "Cleanup folder=" + folder.account + ":" + folder.name +
|
||||
" deleted before=" + new Date(keep_time) + " count=" + messages);
|
||||
}
|
||||
|
||||
// Cleanup message files
|
||||
Log.i(Helper.TAG, "Cleanup message files");
|
||||
File[] messages = new File(getFilesDir(), "messages").listFiles();
|
||||
|
|
Loading…
Reference in New Issue