diff --git a/CHANGELOG.md b/CHANGELOG.md index 26c498db..88354e7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,12 @@ ## untagged -- BREAKING: new required chatmail.ini value - 'mailboxes_dir = /home/vmail/mail/{mail_domain}' - reducing the hardcoding on that directory and improving testability. +- BREAKING: new required chatmail.ini values: + + mailboxes_dir = /home/vmail/mail/{mail_domain} + passdb = /home/vmail/passdb.sqlite + + reducing hardcoding these two paths all over the files, also improving testability. ([#351](https://github.com/deltachat/chatmail/pull/351)) - BREAKING: new required chatmail.ini value 'delete_inactive_users_after = 100' diff --git a/chatmaild/src/chatmaild/config.py b/chatmaild/src/chatmaild/config.py index 2ab4e901..c3562472 100644 --- a/chatmaild/src/chatmaild/config.py +++ b/chatmaild/src/chatmaild/config.py @@ -24,6 +24,7 @@ class Config: self.passthrough_senders = params["passthrough_senders"].split() self.passthrough_recipients = params["passthrough_recipients"].split() self.mailboxes_dir = params["mailboxes_dir"].strip().rstrip("/") + 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"]) self.iroh_relay = params.get("iroh_relay") diff --git a/chatmaild/src/chatmaild/delete_inactive_users.py b/chatmaild/src/chatmaild/delete_inactive_users.py index 2db1d37f..4d23d2e6 100644 --- a/chatmaild/src/chatmaild/delete_inactive_users.py +++ b/chatmaild/src/chatmaild/delete_inactive_users.py @@ -27,6 +27,7 @@ def delete_inactive_users(db, config, CHUNK=100): def main(): - db = Database(sys.argv[1]) - config = read_config(sys.argv[2]) + (cfgpath,) = sys.argv[1:] + config = read_config(cfgpath) + db = Database(config.passdb_path) delete_inactive_users(db, config) diff --git a/chatmaild/src/chatmaild/doveauth.py b/chatmaild/src/chatmaild/doveauth.py index 628c1449..d1bd938d 100644 --- a/chatmaild/src/chatmaild/doveauth.py +++ b/chatmaild/src/chatmaild/doveauth.py @@ -245,9 +245,9 @@ class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer): def main(): - socket = sys.argv[1] - db = Database(sys.argv[2]) - config = read_config(sys.argv[3]) + socket, cfgpath = sys.argv[1:] + config = read_config(cfgpath) + db = Database(config.passdb_path) class Handler(StreamRequestHandler): def handle(self): diff --git a/chatmaild/src/chatmaild/ini/chatmail.ini.f b/chatmaild/src/chatmaild/ini/chatmail.ini.f index fea7b9cd..c78f8059 100644 --- a/chatmaild/src/chatmaild/ini/chatmail.ini.f +++ b/chatmaild/src/chatmaild/ini/chatmail.ini.f @@ -45,6 +45,9 @@ passthrough_recipients = xstore@testrun.org groupsbot@hispanilandia.net # Directory where user mailboxes are stored mailboxes_dir = /home/vmail/mail/{mail_domain} +# user address sqlite database path +passdb_path = /home/vmail/passdb.sqlite + # where the filtermail SMTP service listens filtermail_smtp_port = 10080 diff --git a/chatmaild/src/chatmaild/metadata.py b/chatmaild/src/chatmaild/metadata.py index 5b6d62ed..e7f02478 100644 --- a/chatmaild/src/chatmaild/metadata.py +++ b/chatmaild/src/chatmaild/metadata.py @@ -128,12 +128,12 @@ class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer): def main(): - socket, vmail_dir, config_path = sys.argv[1:] + socket, config_path = sys.argv[1:] config = read_config(config_path) iroh_relay = config.iroh_relay - vmail_dir = Path(vmail_dir) + vmail_dir = Path(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/plugin.py b/chatmaild/src/chatmaild/tests/plugin.py index ac2ebdcc..8f43ccd0 100644 --- a/chatmaild/src/chatmaild/tests/plugin.py +++ b/chatmaild/src/chatmaild/tests/plugin.py @@ -18,7 +18,8 @@ def make_config(tmp_path): def make_conf(mail_domain): basedir = tmp_path.joinpath(f"vmail/{mail_domain}") basedir.mkdir(parents=True, exist_ok=True) - overrides = dict(mailboxes_dir=str(basedir)) + passdb = tmp_path.joinpath("vmail/passdb.sqlite") + overrides = dict(mailboxes_dir=str(basedir), passdb_path=str(passdb)) write_initial_config(inipath, mail_domain=mail_domain, **overrides) return read_config(inipath) diff --git a/chatmaild/src/chatmaild/tests/test_config.py b/chatmaild/src/chatmaild/tests/test_config.py index 99838e49..0310f54b 100644 --- a/chatmaild/src/chatmaild/tests/test_config.py +++ b/chatmaild/src/chatmaild/tests/test_config.py @@ -35,10 +35,13 @@ def test_read_config_testrun(make_config): assert config.passthrough_senders == [] -def test_get_user_maildir(make_config): +def test_config_userstate_paths(make_config, tmp_path): config = make_config("something.testrun.org") mailboxes_dir = Path(config.mailboxes_dir) + passdb_path = Path(config.passdb_path) assert mailboxes_dir.name == "something.testrun.org" + assert passdb_path.name == "passdb.sqlite" + assert passdb_path.is_relative_to(tmp_path) assert config.mail_domain == "something.testrun.org" path = Path(config.get_user_maildir("user1@something.testrun.org")) assert not path.exists() diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index 36548543..84bec704 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -92,7 +92,7 @@ def _install_remote_venv_with_chatmaild(config) -> None: group="root", mode="644", config={ - "mail_domain": config.mail_domain, + "mailboxes_dir": config.mailboxes_dir, "execpath": f"{remote_venv_dir}/bin/chatmail-metrics", }, ) diff --git a/cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 b/cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 index 64aa6550..13b170cb 100644 --- a/cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 +++ b/cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 @@ -1,12 +1,12 @@ # delete all mails after {{ config.delete_mails_after }} days, in the Inbox -2 0 * * * vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/cur/*' -mtime +{{ config.delete_mails_after }} -type f -delete +2 0 * * * vmail find {{ config.mailboxes_dir }} -path '*/cur/*' -mtime +{{ config.delete_mails_after }} -type f -delete # or in any IMAP subfolder -2 0 * * * vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/.*/cur/*' -mtime +{{ config.delete_mails_after }} -type f -delete +2 0 * * * vmail find {{ config.mailboxes_dir }} -path '*/.*/cur/*' -mtime +{{ config.delete_mails_after }} -type f -delete # even if they are unseen -2 0 * * * vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/new/*' -mtime +{{ config.delete_mails_after }} -type f -delete -2 0 * * * vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/.*/new/*' -mtime +{{ config.delete_mails_after }} -type f -delete +2 0 * * * vmail find {{ config.mailboxes_dir }} -path '*/new/*' -mtime +{{ config.delete_mails_after }} -type f -delete +2 0 * * * vmail find {{ config.mailboxes_dir }} -path '*/.*/new/*' -mtime +{{ config.delete_mails_after }} -type f -delete # or only temporary (but then they shouldn't be around after {{ config.delete_mails_after }} days anyway). -2 0 * * * vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/tmp/*' -mtime +{{ config.delete_mails_after }} -type f -delete -2 0 * * * vmail find /home/vmail/mail/{{ config.mail_domain }} -path '*/.*/tmp/*' -mtime +{{ config.delete_mails_after }} -type f -delete -3 0 * * * vmail find /home/vmail/mail/{{ config.mail_domain }} -name 'maildirsize' -type f -delete -4 0 * * * vmail /usr/local/lib/chatmaild/venv/bin/delete_inactive_users /home/vmail/passdb.sqlite /usr/local/lib/chatmaild/chatmail.ini +2 0 * * * vmail find {{ config.mailboxes_dir }} -path '*/tmp/*' -mtime +{{ config.delete_mails_after }} -type f -delete +2 0 * * * vmail find {{ config.mailboxes_dir }} -path '*/.*/tmp/*' -mtime +{{ config.delete_mails_after }} -type f -delete +3 0 * * * vmail find {{ config.mailboxes_dir }} -name 'maildirsize' -type f -delete +4 0 * * * vmail /usr/local/lib/chatmaild/venv/bin/delete_inactive_users /usr/local/lib/chatmaild/chatmail.ini diff --git a/cmdeploy/src/cmdeploy/metrics.cron.j2 b/cmdeploy/src/cmdeploy/metrics.cron.j2 index fbf768ea..8bf036ad 100644 --- a/cmdeploy/src/cmdeploy/metrics.cron.j2 +++ b/cmdeploy/src/cmdeploy/metrics.cron.j2 @@ -1 +1 @@ -*/5 * * * * root {{ config.execpath }} /home/vmail/mail/{{ config.mail_domain }} >/var/www/html/metrics +*/5 * * * * root {{ config.execpath }} {{ config.mailboxes_dir }} >/var/www/html/metrics diff --git a/cmdeploy/src/cmdeploy/service/chatmail-metadata.service.f b/cmdeploy/src/cmdeploy/service/chatmail-metadata.service.f index a3ed9052..b178819d 100644 --- a/cmdeploy/src/cmdeploy/service/chatmail-metadata.service.f +++ b/cmdeploy/src/cmdeploy/service/chatmail-metadata.service.f @@ -2,7 +2,7 @@ Description=Chatmail dict proxy for IMAP METADATA [Service] -ExecStart={execpath} /run/chatmail-metadata/metadata.socket /home/vmail/mail/{mail_domain} {config_path} +ExecStart={execpath} /run/chatmail-metadata/metadata.socket {config_path} Restart=always RestartSec=30 User=vmail diff --git a/cmdeploy/src/cmdeploy/service/doveauth.service.f b/cmdeploy/src/cmdeploy/service/doveauth.service.f index 43b6181a..657430d3 100644 --- a/cmdeploy/src/cmdeploy/service/doveauth.service.f +++ b/cmdeploy/src/cmdeploy/service/doveauth.service.f @@ -2,7 +2,7 @@ Description=Chatmail dict authentication proxy for dovecot [Service] -ExecStart={execpath} /run/doveauth/doveauth.socket /home/vmail/passdb.sqlite {config_path} +ExecStart={execpath} /run/doveauth/doveauth.socket {config_path} Restart=always RestartSec=30 User=vmail diff --git a/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py b/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py index 84010b6a..eea07081 100644 --- a/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py +++ b/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py @@ -108,12 +108,12 @@ def test_exceed_rate_limit(cmsetup, gencreds, maildata, chatmail_config): def test_expunged(remote, chatmail_config): outdated_days = int(chatmail_config.delete_mails_after) + 1 find_cmds = [ - f"find /home/vmail/mail/{chatmail_config.mail_domain} -path '*/cur/*' -mtime +{outdated_days} -type f", - f"find /home/vmail/mail/{chatmail_config.mail_domain} -path '*/.*/cur/*' -mtime +{outdated_days} -type f", - f"find /home/vmail/mail/{chatmail_config.mail_domain} -path '*/new/*' -mtime +{outdated_days} -type f", - f"find /home/vmail/mail/{chatmail_config.mail_domain} -path '*/.*/new/*' -mtime +{outdated_days} -type f", - f"find /home/vmail/mail/{chatmail_config.mail_domain} -path '*/tmp/*' -mtime +{outdated_days} -type f", - f"find /home/vmail/mail/{chatmail_config.mail_domain} -path '*/.*/tmp/*' -mtime +{outdated_days} -type f", + f"find {chatmail_config.mailboxes_dir} -path '*/cur/*' -mtime +{outdated_days} -type f", + f"find {chatmail_config.mailboxes_dir} -path '*/.*/cur/*' -mtime +{outdated_days} -type f", + f"find {chatmail_config.mailboxes_dir} -path '*/new/*' -mtime +{outdated_days} -type f", + f"find {chatmail_config.mailboxes_dir} -path '*/.*/new/*' -mtime +{outdated_days} -type f", + 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", ] for cmd in find_cmds: for line in remote.iter_output(cmd):