mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +00:00
only write last-login files for e-mail address directories
This commit is contained in:
@@ -29,6 +29,8 @@ def write_last_login_to_userdir(userdir, timestamp):
|
|||||||
|
|
||||||
|
|
||||||
def get_last_login_from_userdir(userdir) -> int:
|
def get_last_login_from_userdir(userdir) -> int:
|
||||||
|
if "@" not in userdir.name:
|
||||||
|
return get_daytimestamp(time.time())
|
||||||
target = userdir.joinpath(LAST_LOGIN)
|
target = userdir.joinpath(LAST_LOGIN)
|
||||||
try:
|
try:
|
||||||
return int(target.stat().st_mtime)
|
return int(target.stat().st_mtime)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from chatmaild.lastlogin import get_last_login_from_userdir, write_last_login_to
|
|||||||
|
|
||||||
|
|
||||||
def test_login_timestamps(tmp_path):
|
def test_login_timestamps(tmp_path):
|
||||||
userdir = tmp_path.joinpath("someuser")
|
userdir = tmp_path.joinpath("someuser@chat.example.org")
|
||||||
userdir.mkdir()
|
userdir.mkdir()
|
||||||
write_last_login_to_userdir(userdir, timestamp=100000)
|
write_last_login_to_userdir(userdir, timestamp=100000)
|
||||||
assert get_last_login_from_userdir(userdir) == 86400
|
assert get_last_login_from_userdir(userdir) == 86400
|
||||||
@@ -18,6 +18,13 @@ def test_login_timestamps(tmp_path):
|
|||||||
assert get_last_login_from_userdir(userdir) == 86400 * 2
|
assert get_last_login_from_userdir(userdir) == 86400 * 2
|
||||||
|
|
||||||
|
|
||||||
|
def test_delete_skips_non_email_dir(db, example_config):
|
||||||
|
userdir = example_config.get_user_maildir("something")
|
||||||
|
userdir.mkdir()
|
||||||
|
get_last_login_from_userdir(userdir)
|
||||||
|
assert not list(userdir.iterdir())
|
||||||
|
|
||||||
|
|
||||||
def test_delete_inactive_users(db, example_config):
|
def test_delete_inactive_users(db, example_config):
|
||||||
new = time.time()
|
new = time.time()
|
||||||
old = new - (example_config.delete_inactive_users_after * 86400) - 1
|
old = new - (example_config.delete_inactive_users_after * 86400) - 1
|
||||||
|
|||||||
Reference in New Issue
Block a user