WIP: Remove old messages beyond storage preference
I've started having a bit of a look at this, which is a small part of #453. The aim is to implement a process to clear out older messages which don't fit within the message download period set in the account preferences.
As discussed I've updated the
ImapEngine.CheckFolderSync mechanism to find emails earlier than the download pref and detach them. Initially I was using an approach based on
MessageLocationTable.ordering, but as that's populated from the IMAP message UID which doesn't guarantee order the cleanup could be abandoned early (as it does in some folders on my test account). I've instead implemented a custom query for the cleanup after testing out a number on a populated database (with ~50k messages) to compare performance.
A couple of questions on the changes so far, @mjog:
- Does this approach for the message identification and detachment look suitable? This brute-force cleanup method will add (background) time to each startup, however using the IMAP message UIDs wouldn't clear out all the old messages.
- Is ImapDB.Folder a suitable place for the method?
Questions going forward:
- Work out some way of scheduling a GC run for accounts where the download pref is set to everything (once a day when idle?), and triggering it after obviously related operations (empty spam & empty trash) have completed.
- I'm guessing identifying a daily idle time would be along the lines of tracking last time old message detachment and GC were run, combined with
- The vacuum GC operation is needed to actually free up space, but that needs to lock the DB and run in the foreground. Is that only suitable to run at startup? Or is the engine capable of dealing with a locked DB?
- I think it would be good to trigger the detachment process and GC upon exiting account preferences if the storage period has been reduced?