diff --git a/chatmaild/src/chatmaild/chatmail-metadata.service.f b/chatmaild/src/chatmaild/chatmail-metadata.service.f index 71f3e110..ffd74b10 100644 --- a/chatmaild/src/chatmaild/chatmail-metadata.service.f +++ b/chatmaild/src/chatmaild/chatmail-metadata.service.f @@ -2,7 +2,7 @@ Description=Chatmail dict proxy for IMAP METADATA [Service] -ExecStart={execpath} /run/dovecot/metadata.socket vmail {config_path} +ExecStart={execpath} /run/dovecot/metadata.socket vmail {config_path} /home/vmail/metadata Restart=always RestartSec=30 diff --git a/chatmaild/src/chatmaild/metadata.py b/chatmaild/src/chatmaild/metadata.py index ace92336..3a63f998 100644 --- a/chatmaild/src/chatmaild/metadata.py +++ b/chatmaild/src/chatmaild/metadata.py @@ -1,5 +1,6 @@ import pwd +import pathlib from queue import Queue from threading import Thread from socketserver import ( @@ -145,12 +146,15 @@ class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer): def main(): - socket, username, config = sys.argv[1:] + socket, username, config, metadata_dir = sys.argv[1:] passwd_entry = pwd.getpwnam(username) # XXX config is not currently used config = read_config(config) - notifier = Notifier() + metadata_dir = pathlib.Path(metadata_dir) + if not metadata_dir.exists(): + metadata_dir.mkdir() + notifier = Notifier(metadata_dir) class Handler(StreamRequestHandler): def handle(self): diff --git a/chatmaild/src/chatmaild/tests/test_metadata.py b/chatmaild/src/chatmaild/tests/test_metadata.py index 2a3c122b..5a7e117a 100644 --- a/chatmaild/src/chatmaild/tests/test_metadata.py +++ b/chatmaild/src/chatmaild/tests/test_metadata.py @@ -16,6 +16,22 @@ def notifier(tmp_path): return Notifier(metadata_dir) +def test_notifier_persistence(tmp_path): + metadata_dir = tmp_path.joinpath("metadata") + metadata_dir.mkdir() + notifier1 = Notifier(metadata_dir) + notifier2 = Notifier(metadata_dir) + assert notifier1.get_token(guid="guid00") is None + assert notifier2.get_token(guid="guid00") is None + + notifier1.set_token("guid00", "01234") + notifier1.set_token("guid03", "456") + assert notifier2.get_token("guid00") == "01234" + assert notifier2.get_token("guid03") == "456" + notifier2.del_token("guid00") + assert notifier1.get_token("guid00") is None + + def test_handle_dovecot_request_lookup_fails(notifier): res = handle_dovecot_request("Lpriv/123/chatmail", {}, notifier) assert res == "N\n"