Compare commits

..

4 Commits

Author SHA1 Message Date
holger krekel
bcd9d615d4 remove superflous check in tests 2024-03-20 17:58:59 +01:00
holger krekel
d820644f66 fixes 2024-03-20 17:38:39 +01:00
holger krekel
4e97e4dc3d implement persistence via marshal 2024-03-20 17:02:04 +01:00
holger krekel
92a27983be make notifier take a directory 2024-03-20 16:41:41 +01:00
5 changed files with 34 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
import pwd
from pathlib import Path
import pathlib
from queue import Queue
from threading import Thread
from socketserver import (
@@ -13,6 +13,7 @@ import sys
import logging
import os
import requests
import marshal
DICTPROXY_LOOKUP_CHAR = "L"
@@ -28,19 +29,33 @@ class Notifier:
self.metadata_dir = metadata_dir
self.to_notify_queue = Queue()
def set_token(self, guid, token):
def get_metadata(self, guid):
guid_path = self.metadata_dir.joinpath(guid)
if guid_path.exists():
with guid_path.open("rb") as f:
return marshal.load(f)
return {}
def set_metadata(self, guid, guid_data):
guid_path = self.metadata_dir.joinpath(guid)
write_path = guid_path.with_suffix(".tmp")
write_path.write_text(token)
write_path.rename(guid_path)
with write_path.open("wb") as f:
marshal.dump(guid_data, f)
os.rename(write_path, guid_path)
def set_token(self, guid, token):
guid_data = self.get_metadata(guid)
guid_data["token"] = token
self.set_metadata(guid, guid_data)
def del_token(self, guid):
self.metadata_dir.joinpath(guid).unlink(missing_ok=True)
guid_data = self.get_metadata(guid)
if "token" in guid_data:
del guid_data["token"]
self.set_metadata(guid, guid_data)
def get_token(self, guid):
guid_path = self.metadata_dir / guid
if guid_path.exists():
return guid_path.read_text()
return self.get_metadata(guid).get("token")
def new_message_for_guid(self, guid):
self.to_notify_queue.put(guid)
@@ -136,7 +151,7 @@ def main():
# XXX config is not currently used
config = read_config(config)
metadata_dir = Path(metadata_dir)
metadata_dir = pathlib.Path(metadata_dir)
if not metadata_dir.exists():
metadata_dir.mkdir()
notifier = Notifier(metadata_dir)

View File

@@ -350,18 +350,15 @@ def _configure_dovecot(config: Config, debug: bool = False) -> bool:
need_restart |= lua_push_notification_script.changed
sieve_script = files.put(
src=importlib.resources.files(__package__).joinpath("dovecot/default.sieve"),
src=importlib.resources.files(__package__).joinpath(
"dovecot/default.sieve"
),
dest="/etc/dovecot/default.sieve",
user="root",
group="root",
mode="644",
)
need_restart |= sieve_script.changed
if sieve_script.changed:
server.shell(
name="compile sieve script",
commands=["/usr/bin/sievec /etc/dovecot/default.sieve"],
)
files.template(
src=importlib.resources.files(__package__).joinpath("dovecot/expunge.cron.j2"),
@@ -453,9 +450,7 @@ def check_config(config):
blocked_words = "merlinux schmieder testrun.org".split()
for key in config.__dict__:
value = config.__dict__[key]
if key.startswith("privacy") and any(
x in str(value) for x in blocked_words
):
if key.startswith("privacy") and any(x in str(value) for x in blocked_words):
raise ValueError(
f"please set your own privacy contacts/addresses in {config._inipath}"
)

View File

@@ -5,6 +5,8 @@ import importlib
import subprocess
import datetime
from typing import Optional
class DNS:
def __init__(self, out, mail_domain):

View File

@@ -1,7 +1,5 @@
require ["imap4flags"];
# flag the message so it doesn't cause a push notification
if header :is ["Auto-Submitted"] ["auto-replied", "auto-generated"] {
addflag "$Auto";
}

View File

@@ -63,7 +63,7 @@ class TestEndToEndDeltaChat:
addr = ac2.get_config("addr").lower()
saved_ok = 0
for line in remote.iter_output("journalctl -n0 -f -u dovecot"):
for line in remote.iter_output("journalctl -f -u dovecot"):
if addr not in line:
# print(line)
continue
@@ -112,7 +112,7 @@ class TestEndToEndDeltaChat:
lp.sec("ac1 sends a message and ac2 marks it as seen")
chat = ac1.create_chat(ac2)
msg = chat.send_text("hi")
m = ac2._evtracker.wait_next_incoming_message()
m = ac2.wait_next_incoming_message()
m.mark_seen()
# we can only indirectly wait for mark-seen to cause an smtp-error
lp.sec("try to wait for markseen to complete and check error states")
@@ -132,7 +132,7 @@ def test_hide_senders_ip_address(cmfactory):
chat = cmfactory.get_accepted_chat(user1, user2)
chat.send_text("testing submission header cleanup")
user2._evtracker.wait_next_incoming_message()
user2.wait_next_incoming_message()
user2.direct_imap.select_folder("Inbox")
msg = user2.direct_imap.get_all_messages()[0]
assert public_ip not in msg.obj.as_string()
@@ -146,5 +146,5 @@ def test_echobot(cmfactory, chatmail_config, lp):
text = "hi, I hope you text me back"
chat.send_text(text)
lp.sec("Wait for reply from echobot")
reply = ac._evtracker.wait_next_incoming_message()
reply = ac.wait_next_incoming_message()
assert reply.text == text