mirror of
https://github.com/chatmail/relay.git
synced 2026-05-19 20:38:05 +00:00
Compare commits
7 Commits
link2xt/st
...
hpk/fix-lo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bd6e4f165 | ||
|
|
5fe3a269be | ||
|
|
0b4770018d | ||
|
|
75fcbd03ce | ||
|
|
377121bdee | ||
|
|
e5e58f4e38 | ||
|
|
04517f284c |
22
CHANGELOG.md
Normal file
22
CHANGELOG.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Changelog for chatmail deployment
|
||||||
|
|
||||||
|
## unreleased
|
||||||
|
|
||||||
|
### Changes since March 15th, 2024
|
||||||
|
|
||||||
|
- Fix various tests to pass again with "cmdeploy test".
|
||||||
|
([#245](https://github.com/deltachat/chatmail/pull/245),
|
||||||
|
[#242](https://github.com/deltachat/chatmail/pull/242)
|
||||||
|
|
||||||
|
- Ensure lets-encrypt certificates are reloaded after renewal
|
||||||
|
([#244]) https://github.com/deltachat/chatmail/pull/244
|
||||||
|
|
||||||
|
- Persist tokens to avoid iOS users loosing push-notifications when the
|
||||||
|
chatmail metadata service is restarted (happens regularly during deploys)
|
||||||
|
([#238](https://github.com/deltachat/chatmail/pull/239)
|
||||||
|
|
||||||
|
- Fix failing sieve-script compile errors on incoming messages
|
||||||
|
([#237](https://github.com/deltachat/chatmail/pull/239)
|
||||||
|
|
||||||
|
- Fix quota reporting after expunging of old mails
|
||||||
|
([#233](https://github.com/deltachat/chatmail/pull/239)
|
||||||
@@ -17,6 +17,10 @@ from .config import read_config, Config
|
|||||||
NOCREATE_FILE = "/etc/chatmail-nocreate"
|
NOCREATE_FILE = "/etc/chatmail-nocreate"
|
||||||
|
|
||||||
|
|
||||||
|
class UnknownCommand(ValueError):
|
||||||
|
"""dictproxy handler received an unkown command"""
|
||||||
|
|
||||||
|
|
||||||
def encrypt_password(password: str):
|
def encrypt_password(password: str):
|
||||||
# https://doc.dovecot.org/configuration_manual/authentication/password_schemes/
|
# https://doc.dovecot.org/configuration_manual/authentication/password_schemes/
|
||||||
passhash = crypt.crypt(password, crypt.METHOD_SHA512)
|
passhash = crypt.crypt(password, crypt.METHOD_SHA512)
|
||||||
@@ -127,8 +131,12 @@ def split_and_unescape(s):
|
|||||||
|
|
||||||
|
|
||||||
def handle_dovecot_request(msg, db, config: Config):
|
def handle_dovecot_request(msg, db, config: Config):
|
||||||
|
# see https://doc.dovecot.org/3.0/developer_manual/design/dict_protocol/
|
||||||
short_command = msg[0]
|
short_command = msg[0]
|
||||||
if short_command == "L": # LOOKUP
|
if short_command == "H": # HELLO
|
||||||
|
# we don't do any checking on versions and just return
|
||||||
|
return
|
||||||
|
elif short_command == "L": # LOOKUP
|
||||||
parts = msg[1:].split("\t")
|
parts = msg[1:].split("\t")
|
||||||
|
|
||||||
# Dovecot <2.3.17 has only one part,
|
# Dovecot <2.3.17 has only one part,
|
||||||
@@ -159,7 +167,7 @@ def handle_dovecot_request(msg, db, config: Config):
|
|||||||
reply_command = "N"
|
reply_command = "N"
|
||||||
json_res = json.dumps(res) if res else ""
|
json_res = json.dumps(res) if res else ""
|
||||||
return f"{reply_command}{json_res}\n"
|
return f"{reply_command}{json_res}\n"
|
||||||
return None
|
raise UnknownCommand(msg)
|
||||||
|
|
||||||
|
|
||||||
def handle_dovecot_protocol(rfile, wfile, db: Database, config: Config):
|
def handle_dovecot_protocol(rfile, wfile, db: Database, config: Config):
|
||||||
@@ -167,12 +175,14 @@ def handle_dovecot_protocol(rfile, wfile, db: Database, config: Config):
|
|||||||
msg = rfile.readline().strip().decode()
|
msg = rfile.readline().strip().decode()
|
||||||
if not msg:
|
if not msg:
|
||||||
break
|
break
|
||||||
res = handle_dovecot_request(msg, db, config)
|
try:
|
||||||
if res:
|
res = handle_dovecot_request(msg, db, config)
|
||||||
wfile.write(res.encode("ascii"))
|
except UnknownCommand:
|
||||||
wfile.flush()
|
logging.warning("unknown command: %r", msg)
|
||||||
else:
|
else:
|
||||||
logging.warning("request had no answer: %r", msg)
|
if res:
|
||||||
|
wfile.write(res.encode("ascii"))
|
||||||
|
wfile.flush()
|
||||||
|
|
||||||
|
|
||||||
class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer):
|
class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer):
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ hooks = events.HookCollection()
|
|||||||
@hooks.on(events.RawEvent)
|
@hooks.on(events.RawEvent)
|
||||||
def log_event(event):
|
def log_event(event):
|
||||||
if event.kind == EventType.INFO:
|
if event.kind == EventType.INFO:
|
||||||
logging.info(event.msg)
|
logging.info("%s", event.msg)
|
||||||
elif event.kind == EventType.WARNING:
|
elif event.kind == EventType.WARNING:
|
||||||
logging.warning(event.msg)
|
logging.warning("%s", event.msg)
|
||||||
|
|
||||||
|
|
||||||
@hooks.on(events.RawEvent(EventType.ERROR))
|
@hooks.on(events.RawEvent(EventType.ERROR))
|
||||||
def log_error(event):
|
def log_error(event):
|
||||||
logging.error(event.msg)
|
logging.error("%s", event.msg)
|
||||||
|
|
||||||
|
|
||||||
@hooks.on(events.MemberListChanged)
|
@hooks.on(events.MemberListChanged)
|
||||||
@@ -48,6 +48,9 @@ def on_group_name_changed(event):
|
|||||||
@hooks.on(events.NewMessage(func=lambda e: not e.command))
|
@hooks.on(events.NewMessage(func=lambda e: not e.command))
|
||||||
def echo(event):
|
def echo(event):
|
||||||
snapshot = event.message_snapshot
|
snapshot = event.message_snapshot
|
||||||
|
if snapshot.is_info:
|
||||||
|
# Ignore info messages
|
||||||
|
return
|
||||||
if snapshot.text or snapshot.file:
|
if snapshot.text or snapshot.file:
|
||||||
snapshot.chat.send_message(text=snapshot.text, file=snapshot.file)
|
snapshot.chat.send_message(text=snapshot.text, file=snapshot.file)
|
||||||
|
|
||||||
@@ -59,6 +62,7 @@ def help_command(event):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
path = os.environ.get("PATH")
|
path = os.environ.get("PATH")
|
||||||
venv_path = sys.argv[0].strip("echobot")
|
venv_path = sys.argv[0].strip("echobot")
|
||||||
os.environ["PATH"] = path + ":" + venv_path
|
os.environ["PATH"] = path + ":" + venv_path
|
||||||
@@ -80,5 +84,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import pwd
|
import pwd
|
||||||
|
|
||||||
from pathlib import Path
|
import pathlib
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from socketserver import (
|
from socketserver import (
|
||||||
@@ -13,6 +13,7 @@ import sys
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
import marshal
|
||||||
|
|
||||||
|
|
||||||
DICTPROXY_LOOKUP_CHAR = "L"
|
DICTPROXY_LOOKUP_CHAR = "L"
|
||||||
@@ -28,19 +29,33 @@ class Notifier:
|
|||||||
self.metadata_dir = metadata_dir
|
self.metadata_dir = metadata_dir
|
||||||
self.to_notify_queue = Queue()
|
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)
|
guid_path = self.metadata_dir.joinpath(guid)
|
||||||
write_path = guid_path.with_suffix(".tmp")
|
write_path = guid_path.with_suffix(".tmp")
|
||||||
write_path.write_text(token)
|
with write_path.open("wb") as f:
|
||||||
write_path.rename(guid_path)
|
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):
|
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):
|
def get_token(self, guid):
|
||||||
guid_path = self.metadata_dir / guid
|
return self.get_metadata(guid).get("token")
|
||||||
if guid_path.exists():
|
|
||||||
return guid_path.read_text()
|
|
||||||
|
|
||||||
def new_message_for_guid(self, guid):
|
def new_message_for_guid(self, guid):
|
||||||
self.to_notify_queue.put(guid)
|
self.to_notify_queue.put(guid)
|
||||||
@@ -136,7 +151,7 @@ def main():
|
|||||||
|
|
||||||
# XXX config is not currently used
|
# XXX config is not currently used
|
||||||
config = read_config(config)
|
config = read_config(config)
|
||||||
metadata_dir = Path(metadata_dir)
|
metadata_dir = pathlib.Path(metadata_dir)
|
||||||
if not metadata_dir.exists():
|
if not metadata_dir.exists():
|
||||||
metadata_dir.mkdir()
|
metadata_dir.mkdir()
|
||||||
notifier = Notifier(metadata_dir)
|
notifier = Notifier(metadata_dir)
|
||||||
|
|||||||
@@ -75,6 +75,14 @@ def test_handle_dovecot_request(db, example_config):
|
|||||||
assert userdata["password"].startswith("{SHA512-CRYPT}")
|
assert userdata["password"].startswith("{SHA512-CRYPT}")
|
||||||
|
|
||||||
|
|
||||||
|
def test_handle_dovecot_protocol_hello_is_skipped(db, example_config, caplog):
|
||||||
|
rfile = io.BytesIO(b"H3\t2\t0\t\tauth\n")
|
||||||
|
wfile = io.BytesIO()
|
||||||
|
handle_dovecot_protocol(rfile, wfile, db, example_config)
|
||||||
|
assert wfile.getvalue() == b""
|
||||||
|
assert not caplog.messages
|
||||||
|
|
||||||
|
|
||||||
def test_handle_dovecot_protocol(db, example_config):
|
def test_handle_dovecot_protocol(db, example_config):
|
||||||
rfile = io.BytesIO(
|
rfile = io.BytesIO(
|
||||||
b"H3\t2\t0\t\tauth\nLshared/userdb/foobar@chat.example.org\tfoobar@chat.example.org\n"
|
b"H3\t2\t0\t\tauth\nLshared/userdb/foobar@chat.example.org\tfoobar@chat.example.org\n"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
SHELL=/bin/sh
|
SHELL=/bin/sh
|
||||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
||||||
MAILTO=root
|
MAILTO=root
|
||||||
20 16 * * * root /usr/bin/acmetool --batch reconcile
|
20 16 * * * root /usr/bin/acmetool --batch reconcile && systemctl reload dovecot && systemctl reload postfix
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class TestEndToEndDeltaChat:
|
|||||||
)
|
)
|
||||||
lp.indent("good, message sending failed because quota was exceeded")
|
lp.indent("good, message sending failed because quota was exceeded")
|
||||||
return
|
return
|
||||||
if "saved mail to inbox" in line:
|
if "stored mail into mailbox 'inbox'" in line or "saved mail to inbox" in line:
|
||||||
saved_ok += 1
|
saved_ok += 1
|
||||||
print(f"{saved_ok}: {line}")
|
print(f"{saved_ok}: {line}")
|
||||||
if saved_ok >= num_to_send:
|
if saved_ok >= num_to_send:
|
||||||
|
|||||||
Reference in New Issue
Block a user