From 66c7115cfcc28b450183189b9da6c766ff45d452 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 9 Jul 2024 11:31:05 +0200 Subject: [PATCH] run removal of inactive users daily --- CHANGELOG.md | 3 +++ chatmaild/pyproject.toml | 1 + chatmaild/src/chatmaild/config.py | 1 + chatmaild/src/chatmaild/delete_inactive_users.py | 2 +- chatmaild/src/chatmaild/ini/chatmail.ini.f | 4 ++-- chatmaild/src/chatmaild/tests/test_delete_inactive_users.py | 2 +- cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 | 1 + 7 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af8703f5..e0166196 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## untagged +- BREAKING: new required chatmail.ini value 'delete_inactive_users_after = 25' + which removes users from database and mails after 25 days without any login. + - remove checking of reverse-DNS PTR records. Chatmail-servers don't depend on it and even in the wider e-mail system it's not common anymore. If it's an issue, a chatmail operator can still care to properly set reverse DNS. diff --git a/chatmaild/pyproject.toml b/chatmaild/pyproject.toml index 861ee26e..406e0d0f 100644 --- a/chatmaild/pyproject.toml +++ b/chatmaild/pyproject.toml @@ -26,6 +26,7 @@ chatmail-metadata = "chatmaild.metadata:main" filtermail = "chatmaild.filtermail:main" echobot = "chatmaild.echo:main" chatmail-metrics = "chatmaild.metrics:main" +delete_inactive_users = "chatmaild.delete_inactive_users:main" [project.entry-points.pytest11] "chatmaild.testplugin" = "chatmaild.tests.plugin" diff --git a/chatmaild/src/chatmaild/config.py b/chatmaild/src/chatmaild/config.py index 854cbd33..17ae9cd4 100644 --- a/chatmaild/src/chatmaild/config.py +++ b/chatmaild/src/chatmaild/config.py @@ -4,6 +4,7 @@ import iniconfig def read_config(inipath, mail_basedir=None): + assert Path(inipath).exists(), inipath cfg = iniconfig.IniConfig(inipath) params = cfg.sections["params"] if mail_basedir is None: diff --git a/chatmaild/src/chatmaild/delete_inactive_users.py b/chatmaild/src/chatmaild/delete_inactive_users.py index c20c1650..c2199b9e 100644 --- a/chatmaild/src/chatmaild/delete_inactive_users.py +++ b/chatmaild/src/chatmaild/delete_inactive_users.py @@ -1,5 +1,5 @@ """ -Remove old user accounts +Remove inactive users """ import shutil diff --git a/chatmaild/src/chatmaild/ini/chatmail.ini.f b/chatmaild/src/chatmaild/ini/chatmail.ini.f index f0e36bbd..9e62e1ca 100644 --- a/chatmaild/src/chatmaild/ini/chatmail.ini.f +++ b/chatmaild/src/chatmaild/ini/chatmail.ini.f @@ -8,7 +8,7 @@ mail_domain = {mail_domain} # # -# Restrictions on user addresses +# Restrictions on user addresses # # how many mails a user can send out per minute @@ -20,7 +20,7 @@ max_mailbox_size = 100M # days after which mails are unconditionally deleted delete_mails_after = 20 -# days after which users without a login are deleted (database and mails) +# days after which users without a login are deleted (database and mails) delete_inactive_users_after = 25 # minimum length a username must have diff --git a/chatmaild/src/chatmaild/tests/test_delete_inactive_users.py b/chatmaild/src/chatmaild/tests/test_delete_inactive_users.py index f2e63f38..a51f1ca9 100644 --- a/chatmaild/src/chatmaild/tests/test_delete_inactive_users.py +++ b/chatmaild/src/chatmaild/tests/test_delete_inactive_users.py @@ -1,7 +1,7 @@ from time import time as now -from chatmaild.doveauth import lookup_passdb from chatmaild.delete_inactive_users import delete_inactive_users +from chatmaild.doveauth import lookup_passdb def test_remove_stale_users(db, example_config): diff --git a/cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 b/cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 index d4dc81c4..0d601697 100644 --- a/cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 +++ b/cmdeploy/src/cmdeploy/dovecot/expunge.cron.j2 @@ -9,3 +9,4 @@ 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.lite /usr/local/lib/chatmaild/chatmail.ini