From be3524437186abb64710251258c60c396620508c Mon Sep 17 00:00:00 2001 From: missytake Date: Tue, 3 Feb 2026 12:37:03 +0100 Subject: [PATCH] expire: also expire tmpfs index files if mailbox expires --- chatmaild/src/chatmaild/expire.py | 11 +++++++---- chatmaild/src/chatmaild/tests/test_expire.py | 14 ++++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/chatmaild/src/chatmaild/expire.py b/chatmaild/src/chatmaild/expire.py index 3074073a..7b83051b 100644 --- a/chatmaild/src/chatmaild/expire.py +++ b/chatmaild/src/chatmaild/expire.py @@ -24,7 +24,7 @@ def iter_mailboxes(basedir, maxnum): for name in os_listdir_if_exists(basedir)[:maxnum]: if "@" in name: - yield MailboxStat(basedir + "/" + name) + yield MailboxStat(basedir + "/" + name, name) def get_file_entry(path): @@ -49,8 +49,9 @@ def os_listdir_if_exists(path): class MailboxStat: last_login = None - def __init__(self, basedir): + def __init__(self, basedir, name): self.basedir = str(basedir) + self.name = name self.messages = [] self.extrafiles = [] self.scandir(self.basedir) @@ -90,11 +91,13 @@ class Expiry: self.all_files = 0 self.start = time.time() - def remove_mailbox(self, mboxdir): + def remove_mailbox(self, mboxdir, name): if self.verbose: print_info(f"removing {mboxdir}") if not self.dry: shutil.rmtree(mboxdir) + if self.config.tmpfs_index: + shutil.rmtree("/dev/shm/" + name) self.del_mboxes += 1 def remove_file(self, path, mtime=None): @@ -121,7 +124,7 @@ class Expiry: self.all_mboxes += 1 changed = False if mbox.last_login and mbox.last_login < cutoff_without_login: - self.remove_mailbox(mbox.basedir) + self.remove_mailbox(mbox.basedir, mbox.name) return mboxname = os.path.basename(mbox.basedir) diff --git a/chatmaild/src/chatmaild/tests/test_expire.py b/chatmaild/src/chatmaild/tests/test_expire.py index fcdb4506..843b9aea 100644 --- a/chatmaild/src/chatmaild/tests/test_expire.py +++ b/chatmaild/src/chatmaild/tests/test_expire.py @@ -43,20 +43,22 @@ def create_new_messages(basedir, relpaths, size=1000, days=0): @pytest.fixture def mbox1(example_config): - mboxdir = example_config.mailboxes_dir.joinpath("mailbox1@example.org") + addr = "mailbox1@example.org" + mboxdir = example_config.mailboxes_dir.joinpath(addr) mboxdir.mkdir() fill_mbox(mboxdir) - return MailboxStat(mboxdir) + return MailboxStat(mboxdir, addr) def test_deltachat_folder(example_config): """Test old setups that might have a .DeltaChat folder where messages also need to get removed.""" - mboxdir = example_config.mailboxes_dir.joinpath("mailbox1@example.org") + addr = "mailbox1@example.org" + mboxdir = example_config.mailboxes_dir.joinpath(addr) mboxdir.mkdir() mbox2dir = mboxdir.joinpath(".DeltaChat") mbox2dir.mkdir() fill_mbox(mbox2dir) - mb = MailboxStat(mboxdir) + mb = MailboxStat(mboxdir, addr) assert len(mb.messages) == 2 @@ -86,13 +88,13 @@ def test_stats_mailbox(mbox1): create_new_messages(mbox1.basedir, ["large-extra"], size=1000) create_new_messages(mbox1.basedir, ["index-something"], size=3) - mbox2 = MailboxStat(mbox1.basedir) + mbox2 = MailboxStat(mbox1.basedir, mbox1.name) assert len(mbox2.extrafiles) == 5 assert mbox2.extrafiles[0].size == 1000 # cope well with mailbox dirs that have no password (for whatever reason) Path(mbox1.basedir).joinpath("password").unlink() - mbox3 = MailboxStat(mbox1.basedir) + mbox3 = MailboxStat(mbox1.basedir, mbox1.name) assert mbox3.last_login is None