From ae6b89f936521becf201c3d092aea6334a249fde Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 26 Aug 2026 16:59:26 +0200 Subject: [PATCH] fix: actually use UTC time instead of just seemingly using it datetime.now(timezone.utc).timestamp() is actually 7200 seconds in the past. The Python deprecation warning of utcnow() warning actually pointed there. --- chatmaild/src/chatmaild/expire.py | 2 +- chatmaild/src/chatmaild/fsreport.py | 3 ++- chatmaild/src/chatmaild/tests/test_expire.py | 9 +++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/chatmaild/src/chatmaild/expire.py b/chatmaild/src/chatmaild/expire.py index 783f63f9..e4324c3d 100644 --- a/chatmaild/src/chatmaild/expire.py +++ b/chatmaild/src/chatmaild/expire.py @@ -259,7 +259,7 @@ def daily_expire_main(args=None): args = parser.parse_args(args) config = read_config(args.chatmail_ini) - now = datetime.utcnow().timestamp() + now = time.time() if args.days: now = now - 86400 * int(args.days) diff --git a/chatmaild/src/chatmaild/fsreport.py b/chatmaild/src/chatmaild/fsreport.py index a6901d22..70416009 100644 --- a/chatmaild/src/chatmaild/fsreport.py +++ b/chatmaild/src/chatmaild/fsreport.py @@ -27,6 +27,7 @@ to also write legacy metrics.py style output (default: /var/www/html/metrics): import os import tempfile +import time from argparse import ArgumentParser from datetime import datetime @@ -264,7 +265,7 @@ def main(args=None): config = read_config(args.chatmail_ini) - now = datetime.utcnow().timestamp() + now = time.time() if args.days: now = now - 86400 * int(args.days) diff --git a/chatmaild/src/chatmaild/tests/test_expire.py b/chatmaild/src/chatmaild/tests/test_expire.py index c6ad7f1d..c99e33b6 100644 --- a/chatmaild/src/chatmaild/tests/test_expire.py +++ b/chatmaild/src/chatmaild/tests/test_expire.py @@ -3,7 +3,6 @@ import os import random import shutil import time -from datetime import datetime from fnmatch import fnmatch from pathlib import Path @@ -41,7 +40,7 @@ def fill_mbox(folderdir): def create_new_messages(basedir, relpaths, size=1000, days=0): - now = datetime.utcnow().timestamp() + now = time.time() for relpath in relpaths: msg_path = Path(basedir).joinpath(relpath) @@ -112,9 +111,7 @@ def test_mbox_without_password(mbox1, example_config, capsys): mbox_rescan = MailboxStat(mbox1.basedir) assert mbox_rescan.last_login is None - exp = Expiry( - example_config, dry=False, now=datetime.now().timestamp(), verbose=False - ) + exp = Expiry(example_config, dry=False, now=time.time(), verbose=False) exp.process_mailbox_stat(mbox_rescan) out, err = capsys.readouterr() assert "doesn't have last_login but isn't empty" in err @@ -152,7 +149,7 @@ def test_report_mdir_filters_by_path(mbox1, example_config): """Test that Report with mdir='cur' only counts messages in cur/ subdirectory.""" from chatmaild.fsreport import Report - now = datetime.utcnow().timestamp() + now = time.time() # Set password mtime to old enough so min_login_age check passes password = Path(mbox1.basedir).joinpath("password")