diff --git a/chatmaild/src/chatmaild/metadata.py b/chatmaild/src/chatmaild/metadata.py index 6a7f0cf..22b19e5 100644 --- a/chatmaild/src/chatmaild/metadata.py +++ b/chatmaild/src/chatmaild/metadata.py @@ -30,17 +30,22 @@ class Notifier: def set_token(self, guid, token): guid_path = self.metadata_dir.joinpath(guid) - write_path = guid_path.with_suffix(".tmp") + if not guid_path.exists(): + guid_path.mkdir() + token_path = guid_path / "token" + write_path = token_path.with_suffix(".tmp") write_path.write_text(token) - write_path.rename(guid_path) + write_path.rename(token_path) def del_token(self, guid): - self.metadata_dir.joinpath(guid).unlink(missing_ok=True) + self.metadata_dir.joinpath(guid).joinpath("token").unlink(missing_ok=True) def get_token(self, guid): guid_path = self.metadata_dir / guid if guid_path.exists(): - return guid_path.read_text() + token_path = guid_path / "token" + if token_path.exists(): + return token_path.read_text() def new_message_for_guid(self, guid): self.to_notify_queue.put(guid) diff --git a/chatmaild/src/chatmaild/tests/test_metadata.py b/chatmaild/src/chatmaild/tests/test_metadata.py index e5d38ad..cd9c948 100644 --- a/chatmaild/src/chatmaild/tests/test_metadata.py +++ b/chatmaild/src/chatmaild/tests/test_metadata.py @@ -31,6 +31,11 @@ def test_notifier_persistence(tmp_path): assert notifier1.get_token("guid00") is None +def test_notifier_delete_without_set(notifier): + notifier.del_token("guid00") + assert not notifier.get_token("guid00") + + def test_handle_dovecot_request_lookup_fails(notifier): res = handle_dovecot_request("Lpriv/123/chatmail", {}, notifier) assert res == "N\n"