From a78c9035217af2fd1899ce7fdc0db7fc0dc13c7e Mon Sep 17 00:00:00 2001 From: missytake Date: Fri, 11 Apr 2025 15:00:04 +0200 Subject: [PATCH] cmdeploy: config value for deleting large messages after X days --- CHANGELOG.md | 2 ++ chatmaild/src/chatmaild/config.py | 1 + chatmaild/src/chatmaild/ini/chatmail.ini.f | 3 +++ chatmaild/src/chatmaild/tests/test_config.py | 1 + cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 | 2 +- cmdeploy/src/cmdeploy/tests/online/test_1_basic.py | 2 ++ 6 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da2c4b4b..117e479c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## untagged +- Add config value after how many days large files are deleted + ([#555](https://github.com/chatmail/relay/pull/555)) ## 1.6.0 2025-04-11 diff --git a/chatmaild/src/chatmaild/config.py b/chatmaild/src/chatmaild/config.py index 8edb1929..971906bd 100644 --- a/chatmaild/src/chatmaild/config.py +++ b/chatmaild/src/chatmaild/config.py @@ -26,6 +26,7 @@ class Config: self.max_mailbox_size = params["max_mailbox_size"] self.max_message_size = int(params.get("max_message_size", "31457280")) self.delete_mails_after = params["delete_mails_after"] + self.delete_large_after = params["delete_large_after"] self.delete_inactive_users_after = int(params["delete_inactive_users_after"]) self.username_min_length = int(params["username_min_length"]) self.username_max_length = int(params["username_max_length"]) diff --git a/chatmaild/src/chatmaild/ini/chatmail.ini.f b/chatmaild/src/chatmaild/ini/chatmail.ini.f index d9e5261a..38743d56 100644 --- a/chatmaild/src/chatmaild/ini/chatmail.ini.f +++ b/chatmaild/src/chatmaild/ini/chatmail.ini.f @@ -23,6 +23,9 @@ max_message_size = 31457280 # days after which mails are unconditionally deleted delete_mails_after = 20 +# days after which large messages (>200k) are unconditionally deleted +delete_large_after = 7 + # days after which users without a successful login are deleted (database and mails) delete_inactive_users_after = 90 diff --git a/chatmaild/src/chatmaild/tests/test_config.py b/chatmaild/src/chatmaild/tests/test_config.py index 542084a9..6ef3c61e 100644 --- a/chatmaild/src/chatmaild/tests/test_config.py +++ b/chatmaild/src/chatmaild/tests/test_config.py @@ -35,6 +35,7 @@ def test_read_config_testrun(make_config): assert config.max_user_send_per_minute == 60 assert config.max_mailbox_size == "100M" assert config.delete_mails_after == "20" + assert config.delete_large_after == "7" assert config.username_min_length == 9 assert config.username_max_length == 9 assert config.password_min_length == 9 diff --git a/cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 b/cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 index 73ab321a..9eb27182 100644 --- a/cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 +++ b/cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 @@ -1,5 +1,5 @@ # delete already seen big mails after 7 days, in the INBOX -2 0 * * * vmail find {{ config.mailboxes_dir }} -path '*/cur/*' -mtime +7 -size +200k -type f -delete +2 0 * * * vmail find {{ config.mailboxes_dir }} -path '*/cur/*' -mtime +{{ config.delete_large_after }} -size +200k -type f -delete # delete all mails after {{ config.delete_mails_after }} days, in the Inbox 2 0 * * * vmail find {{ config.mailboxes_dir }} -path '*/cur/*' -mtime +{{ config.delete_mails_after }} -type f -delete # or in any IMAP subfolder diff --git a/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py b/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py index e2f19032..6ab96904 100644 --- a/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py +++ b/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py @@ -182,6 +182,8 @@ def test_expunged(remote, chatmail_config): f"find {chatmail_config.mailboxes_dir} -path '*/tmp/*' -mtime +{outdated_days} -type f", f"find {chatmail_config.mailboxes_dir} -path '*/.*/tmp/*' -mtime +{outdated_days} -type f", ] + outdated_days = int(chatmail_config.delete_large_after) + 1 + find_cmds.append("find {chatmail_config.mailboxes_dir} -path '*/cur/*' -mtime +{outdated_days} -size +200k -type f") for cmd in find_cmds: for line in remote.iter_output(cmd): assert not line