From 9b1d36113f85675027bdcac476198f9af2875b40 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 23 Nov 2026 22:34:06 +0100 Subject: [PATCH] fix: chatmail-expire dry run no longer deletes over-quota messages --- chatmaild/src/chatmaild/expire.py | 7 ++++--- chatmaild/src/chatmaild/tests/test_expire.py | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/chatmaild/src/chatmaild/expire.py b/chatmaild/src/chatmaild/expire.py index e4324c3d..d2fac149 100644 --- a/chatmaild/src/chatmaild/expire.py +++ b/chatmaild/src/chatmaild/expire.py @@ -99,7 +99,7 @@ def scan_mailbox_messages(mbox): return messages -def expire_to_target(mbox, target_bytes): +def expire_to_target(mbox, target_bytes, dry=False): messages = scan_mailbox_messages(mbox) total_size = sum(m.quota_size for m in messages) # Keep recent 24 hours of messages protected from expiry because @@ -112,7 +112,8 @@ def expire_to_target(mbox, target_bytes): break if entry.mtime > undeletable_messages_cutoff: break - (mbox / entry.path).unlink(missing_ok=True) + if not dry: + (mbox / entry.path).unlink(missing_ok=True) total_size -= entry.quota_size removed += 1 @@ -202,7 +203,7 @@ class Expiry: target_bytes = ( self.config.max_mailbox_size_mb * 1024 * 1024 * QUOTA_CLEANUP_FACTOR ) - removed = expire_to_target(Path(mbox.basedir), target_bytes) + removed = expire_to_target(Path(mbox.basedir), target_bytes, dry=self.dry) if removed: changed = True self.del_files += removed diff --git a/chatmaild/src/chatmaild/tests/test_expire.py b/chatmaild/src/chatmaild/tests/test_expire.py index c99e33b6..d80ea581 100644 --- a/chatmaild/src/chatmaild/tests/test_expire.py +++ b/chatmaild/src/chatmaild/tests/test_expire.py @@ -183,8 +183,13 @@ def test_report_mdir_filters_by_path(mbox1, example_config): def test_expiry_cli_basic(example_config, mbox1): + mboxdir = Path(mbox1.basedir) + p1 = _create_message(mboxdir, "cur", 400 * MB, days_old=2, disk_size=10) + p2 = _create_message(mboxdir, "cur", 400 * MB, days_old=2, disk_size=10) args = (str(example_config._inipath),) expiry_main(args) + assert p1.exists() and p2.exists() + assert mboxdir.joinpath("maildirsize").exists() def test_expiry_cli_old_files(capsys, example_config, mbox1):