From 794a0608a1599e4afadd47a1a4b3dc35d38b81cf Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 10 Jul 2024 11:50:10 +0200 Subject: [PATCH] Path-ify config.mailboxes_dir --- chatmaild/src/chatmaild/config.py | 4 ++-- chatmaild/src/chatmaild/metadata.py | 3 +-- chatmaild/src/chatmaild/tests/test_config.py | 2 +- chatmaild/src/chatmaild/tests/test_delete_inactive_users.py | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/chatmaild/src/chatmaild/config.py b/chatmaild/src/chatmaild/config.py index c3562472..06458aaf 100644 --- a/chatmaild/src/chatmaild/config.py +++ b/chatmaild/src/chatmaild/config.py @@ -23,7 +23,7 @@ class Config: self.password_min_length = int(params["password_min_length"]) self.passthrough_senders = params["passthrough_senders"].split() self.passthrough_recipients = params["passthrough_recipients"].split() - self.mailboxes_dir = params["mailboxes_dir"].strip().rstrip("/") + self.mailboxes_dir = Path(params["mailboxes_dir"].strip()) self.passdb_path = params["passdb_path"].strip().rstrip("/") self.filtermail_smtp_port = int(params["filtermail_smtp_port"]) self.postfix_reinject_port = int(params["postfix_reinject_port"]) @@ -38,7 +38,7 @@ class Config: def get_user_maildir(self, addr): if addr and addr != "." and "/" not in addr: - res = Path(self.mailboxes_dir).joinpath(addr).resolve() + res = self.mailboxes_dir.joinpath(addr).resolve() if res.is_relative_to(self.mailboxes_dir): return str(res) raise ValueError(f"invalid address {addr!r}") diff --git a/chatmaild/src/chatmaild/metadata.py b/chatmaild/src/chatmaild/metadata.py index e7f02478..8ef66f1e 100644 --- a/chatmaild/src/chatmaild/metadata.py +++ b/chatmaild/src/chatmaild/metadata.py @@ -1,7 +1,6 @@ import logging import os import sys -from pathlib import Path from socketserver import ( StreamRequestHandler, ThreadingMixIn, @@ -133,7 +132,7 @@ def main(): config = read_config(config_path) iroh_relay = config.iroh_relay - vmail_dir = Path(config.mailboxes_dir) + vmail_dir = config.mailboxes_dir if not vmail_dir.exists(): logging.error("vmail dir does not exist: %r", vmail_dir) return 1 diff --git a/chatmaild/src/chatmaild/tests/test_config.py b/chatmaild/src/chatmaild/tests/test_config.py index 0310f54b..94f671c8 100644 --- a/chatmaild/src/chatmaild/tests/test_config.py +++ b/chatmaild/src/chatmaild/tests/test_config.py @@ -37,7 +37,7 @@ def test_read_config_testrun(make_config): def test_config_userstate_paths(make_config, tmp_path): config = make_config("something.testrun.org") - mailboxes_dir = Path(config.mailboxes_dir) + mailboxes_dir = config.mailboxes_dir passdb_path = Path(config.passdb_path) assert mailboxes_dir.name == "something.testrun.org" assert passdb_path.name == "passdb.sqlite" diff --git a/chatmaild/src/chatmaild/tests/test_delete_inactive_users.py b/chatmaild/src/chatmaild/tests/test_delete_inactive_users.py index 560e74ef..418894e0 100644 --- a/chatmaild/src/chatmaild/tests/test_delete_inactive_users.py +++ b/chatmaild/src/chatmaild/tests/test_delete_inactive_users.py @@ -41,7 +41,7 @@ def test_remove_stale_users(db, example_config): delete_inactive_users(db, example_config) - for p in Path(example_config.mailboxes_dir).iterdir(): + for p in example_config.mailboxes_dir.iterdir(): assert not p.name.startswith("old") for addr in to_remove: