mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +00:00
fix: expire messages also from DeltaChat IMAP subfolders
This commit is contained in:
@@ -63,21 +63,28 @@ class MailboxStat:
|
|||||||
os.chdir(self.basedir)
|
os.chdir(self.basedir)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return
|
return
|
||||||
for name in os_listdir_if_exists("."):
|
try:
|
||||||
|
self.scandir(".")
|
||||||
|
finally:
|
||||||
|
os.chdir(old_cwd)
|
||||||
|
|
||||||
|
def scandir(self, dirname):
|
||||||
|
for name in os_listdir_if_exists(dirname):
|
||||||
|
relpath = f"{dirname}/{name}"
|
||||||
if name in ("cur", "new", "tmp"):
|
if name in ("cur", "new", "tmp"):
|
||||||
for msg_name in os_listdir_if_exists(name):
|
for msg_name in os_listdir_if_exists(relpath):
|
||||||
entry = get_file_entry(f"{name}/{msg_name}")
|
entry = get_file_entry(f"{relpath}/{msg_name}")
|
||||||
if entry is not None:
|
if entry is not None:
|
||||||
self.messages.append(entry)
|
self.messages.append(entry)
|
||||||
|
elif relpath == "./.DeltaChat":
|
||||||
|
self.scandir(name)
|
||||||
else:
|
else:
|
||||||
entry = get_file_entry(name)
|
entry = get_file_entry(relpath)
|
||||||
if entry is not None:
|
if entry is not None:
|
||||||
self.extrafiles.append(entry)
|
self.extrafiles.append(entry)
|
||||||
if name == "password":
|
if name == "password":
|
||||||
self.last_login = entry.mtime
|
self.last_login = entry.mtime
|
||||||
self.extrafiles.sort(key=lambda x: -x.size)
|
self.extrafiles.sort(key=lambda x: -x.size)
|
||||||
os.chdir(old_cwd)
|
|
||||||
|
|
||||||
|
|
||||||
def print_info(msg):
|
def print_info(msg):
|
||||||
@@ -150,7 +157,7 @@ class Expiry:
|
|||||||
self.remove_file(message.relpath, mtime=message.mtime)
|
self.remove_file(message.relpath, mtime=message.mtime)
|
||||||
elif message.size > 200000 and message.mtime < cutoff_large_mails:
|
elif message.size > 200000 and message.mtime < cutoff_large_mails:
|
||||||
# we only remove noticed large files (not unnoticed ones in new/)
|
# we only remove noticed large files (not unnoticed ones in new/)
|
||||||
if message.relpath.startswith("cur/"):
|
if "cur" in message.relpath.split("/"):
|
||||||
self.remove_file(message.relpath, mtime=message.mtime)
|
self.remove_file(message.relpath, mtime=message.mtime)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -17,9 +17,7 @@ from chatmaild.expire import main as expiry_main
|
|||||||
from chatmaild.fsreport import main as report_main
|
from chatmaild.fsreport import main as report_main
|
||||||
|
|
||||||
|
|
||||||
def fill_mbox(basedir):
|
def fill_mbox(basedir1):
|
||||||
basedir1 = basedir.joinpath("mailbox1@example.org")
|
|
||||||
basedir1.mkdir()
|
|
||||||
password = basedir1.joinpath("password")
|
password = basedir1.joinpath("password")
|
||||||
password.write_text("xxx")
|
password.write_text("xxx")
|
||||||
basedir1.joinpath("maildirsize").write_text("xxx")
|
basedir1.joinpath("maildirsize").write_text("xxx")
|
||||||
@@ -29,7 +27,6 @@ def fill_mbox(basedir):
|
|||||||
|
|
||||||
create_new_messages(basedir1, ["cur/msg1"], size=500)
|
create_new_messages(basedir1, ["cur/msg1"], size=500)
|
||||||
create_new_messages(basedir1, ["new/msg2"], size=600)
|
create_new_messages(basedir1, ["new/msg2"], size=600)
|
||||||
return basedir1
|
|
||||||
|
|
||||||
|
|
||||||
def create_new_messages(basedir, relpaths, size=1000, days=0):
|
def create_new_messages(basedir, relpaths, size=1000, days=0):
|
||||||
@@ -45,8 +42,21 @@ def create_new_messages(basedir, relpaths, size=1000, days=0):
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mbox1(example_config):
|
def mbox1(example_config):
|
||||||
basedir1 = fill_mbox(example_config.mailboxes_dir)
|
mboxdir = example_config.mailboxes_dir.joinpath("mailbox1@example.org")
|
||||||
return MailboxStat(basedir1)
|
mboxdir.mkdir()
|
||||||
|
fill_mbox(mboxdir)
|
||||||
|
return MailboxStat(mboxdir)
|
||||||
|
|
||||||
|
|
||||||
|
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")
|
||||||
|
mboxdir.mkdir()
|
||||||
|
mbox2dir = mboxdir.joinpath(".DeltaChat")
|
||||||
|
mbox2dir.mkdir()
|
||||||
|
fill_mbox(mbox2dir)
|
||||||
|
mb = MailboxStat(mboxdir)
|
||||||
|
assert len(mb.messages) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_filentry_ordering(tmp_path):
|
def test_filentry_ordering(tmp_path):
|
||||||
|
|||||||
Reference in New Issue
Block a user