mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +00:00
Compare commits
16 Commits
config-emp
...
hagi/#295-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e934bdea4 | ||
|
|
3f197695d9 | ||
|
|
8ad72deeb2 | ||
|
|
ea817a2088 | ||
|
|
d9bf2b57a5 | ||
|
|
b4b0a098d1 | ||
|
|
410eae3be4 | ||
|
|
7bc3b11594 | ||
|
|
7bcf027837 | ||
|
|
64de63815d | ||
|
|
07802569ef | ||
|
|
a77e03c8a1 | ||
|
|
7f5ae11591 | ||
|
|
a5a486e8c5 | ||
|
|
1a50e5b783 | ||
|
|
06f3bbf6cd |
@@ -26,6 +26,7 @@ chatmail-metadata = "chatmaild.metadata:main"
|
||||
filtermail = "chatmaild.filtermail:main"
|
||||
echobot = "chatmaild.echo:main"
|
||||
chatmail-metrics = "chatmaild.metrics:main"
|
||||
rm_accounts = "chatmaild.rm_accounts:main"
|
||||
|
||||
[project.entry-points.pytest11]
|
||||
"chatmaild.testplugin" = "chatmaild.tests.plugin"
|
||||
|
||||
@@ -13,6 +13,7 @@ class Config:
|
||||
self.max_user_send_per_minute = int(params["max_user_send_per_minute"])
|
||||
self.max_mailbox_size = params["max_mailbox_size"]
|
||||
self.delete_mails_after = params["delete_mails_after"]
|
||||
self.delete_accounts_after = int(params["delete_accounts_after"])
|
||||
self.username_min_length = int(params["username_min_length"])
|
||||
self.username_max_length = int(params["username_max_length"])
|
||||
self.password_min_length = int(params["password_min_length"])
|
||||
|
||||
@@ -106,7 +106,8 @@ def lookup_passdb(db, config: Config, user, cleartext_password):
|
||||
if userdata:
|
||||
# Update last login time.
|
||||
conn.execute(
|
||||
"UPDATE users SET last_login=? WHERE addr=?", (int(time.time()), user)
|
||||
"UPDATE users SET last_login=? WHERE addr=?",
|
||||
(int(time.time() // 86400), user),
|
||||
)
|
||||
|
||||
userdata["home"] = f"/home/vmail/mail/{config.mail_domain}/{user}"
|
||||
|
||||
@@ -20,6 +20,9 @@ max_mailbox_size = 100M
|
||||
# days after which mails are unconditionally deleted
|
||||
delete_mails_after = 20
|
||||
|
||||
# days after which accounts are deleted if nobody logged in
|
||||
delete_accounts_after = 25
|
||||
|
||||
# minimum length a username must have
|
||||
username_min_length = 9
|
||||
|
||||
|
||||
37
chatmaild/src/chatmaild/rm_accounts.py
Normal file
37
chatmaild/src/chatmaild/rm_accounts.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import sys
|
||||
import time
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from .config import read_config
|
||||
from .database import Database
|
||||
|
||||
|
||||
def remove_users(db: Database, cutoff_date: int):
|
||||
with db.write_transaction() as conn:
|
||||
delete_query = "DELETE FROM users WHERE last_login <?"
|
||||
conn.execute(delete_query, (cutoff_date))
|
||||
|
||||
|
||||
def remove_user_data(db: Database, cutoff_date: int, vmail_basedir: Path):
|
||||
"""Collects all users where last_login < cutoff_date and deletes corresponding directories."""
|
||||
|
||||
with db.write_transaction() as conn:
|
||||
select_query = "SELECT user FROM users WHERE last_login <?"
|
||||
cursor = conn.execute(select_query, (cutoff_date,))
|
||||
usernames = cursor.fetchall()
|
||||
|
||||
for username in usernames:
|
||||
user_dir = vmail_basedir / username[0]
|
||||
if user_dir.exists() and user_dir.is_dir():
|
||||
shutil.rmtree(user_dir, ignore_errors=True)
|
||||
print(f"Deleted directory: {user_dir}")
|
||||
|
||||
|
||||
def main():
|
||||
db = Database(sys.argv[2])
|
||||
config = read_config(sys.argv[3])
|
||||
today = int(time.time() // 86400)
|
||||
|
||||
cutoff_date = today - config.delete_accounts_after
|
||||
remove_user_data(db, cutoff_date)
|
||||
@@ -649,5 +649,3 @@ def deploy_chatmail(config_path: Path) -> None:
|
||||
name="Ensure cron is installed",
|
||||
packages=["cron"],
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user