Option to clean up old attachments on a schedule#11061
Conversation
|
Missing report label. Set exactly one of: |
| android:key="account_attachment_cleanup" | ||
| android:summary="@string/account_settings_attachment_cleanup_summary" | ||
| android:title="@string/account_settings_attachment_cleanup_label" | ||
| /> |
There was a problem hiding this comment.
Intentionally wired into the existing legacy account settings screen because account settings still use this
| import net.thunderbird.core.common.mail.Protocols | ||
| import net.thunderbird.core.logging.legacy.Log | ||
|
|
||
| class AttachmentCleanupWorkerManager( |
There was a problem hiding this comment.
Cleanup work is scheduled only for IMAP accounts with a non-zero retention value. Disabling the setting or switching to a non-IMAP account cancels both periodic and pending one-time cleanup work.
| BackgroundOps.NEVER -> true | ||
| BackgroundOps.ALWAYS -> false | ||
| BackgroundOps.WHEN_CHECKED_AUTO_SYNC -> !ContentResolver.getMasterSyncAutomatically() | ||
| } |
There was a problem hiding this comment.
Attachment cleanup follows the existing background-work policy, including WHEN_CHECKED_AUTO_SYNC via Android master sync, so it should not run when the user has disabled background account work.
| import com.fsck.k9.mailstore.LockableDatabase | ||
| import net.thunderbird.core.common.mail.Flag | ||
|
|
||
| internal class AttachmentCleanupOperations( |
There was a problem hiding this comment.
The SQL query only pre-filters candidate parts; attachment detection is done by parsing disposition so inline parts with filenames like 'attachment.png' are not removed.
| } | ||
| } | ||
|
|
||
| private fun SQLiteDatabase.markPartsAsMissing(messagePartIds: List<Long>) { |
There was a problem hiding this comment.
Cleanup removes only the local payload and marks the part as missing. It preserves message part metadata such as filename/server reference so the attachment can be fetched again on demand.
|
IMO this is ready for review. The jankiest part is the attachment detection - we finds candidates by doing a SQL LIKE over raw headers, then parse in code to decide whether the part is really an attachment. This is kinda fragile and expensive - lots of redundant work on every run. The cleaner version would store attachment-ness as structured data when saving the message part, then the cleanup can query an indexed column instead of interpreting MIME headers. But I did not want to introduce a schema change and a migration rn |
Summary
Adds an account-level setting to remove locally downloaded attachments from IMAP messages older than a selected age. Intention is to save local space.
Message and attachment metadata are preserved so attachments can still be fetched again from the server when requested.
I wired this into the existing legacy account settings/storage path because account settings are still mostly there.
Notes