validate list name
This fixes #228
diff --git a/server/endpoints/mgmt.py b/server/endpoints/mgmt.py
index 7f47781..8a0dfe5 100644
--- a/server/endpoints/mgmt.py
+++ b/server/endpoints/mgmt.py
@@ -166,6 +166,12 @@
if new_body and not isinstance(new_body, str):
return user_error("Email body must be a text string!")
+ # extra list validation
+ if new_list:
+ new_forum = new_list.strip("<>").replace(".", "@", 1)
+ if not new_forum in server.data.lists:
+ return user_error(f"New list id: '{new_forum}' is not an existing list")
+
email = await plugins.messages.get_email(session, permalink=doc)
if email:
@@ -203,7 +209,7 @@
if not new_lid == origin_lid:
email["list"] = new_lid
email["list_raw"] = new_lid
- email["forum"] = new_lid.strip("<>").replace(".", "@", 1)
+ email["forum"] = new_forum
changes.append(f"Listid {origin_lid} => {new_lid}")
hide_source = True
diff --git a/test/itest_integration.py b/test/itest_integration.py
index 606a4cd..4a5ff21 100644
--- a/test/itest_integration.py
+++ b/test/itest_integration.py
@@ -245,6 +245,12 @@
text = mgmt_get_text({"action": 'edit', "document": 'abcd', "list": "True"}, admin_cookies, 400)
assert "List ID field must match" in text
+ text = mgmt_get_text({"action": 'edit', "document": 'abcd', "list": "a.b.c.d"}, admin_cookies, 400)
+ assert "is not an existing list" in text
+
+ text = mgmt_get_text({"action": 'edit', "document": 'abcd', "list": "dev.ponymail.apache.org"}, admin_cookies, 404)
+ assert "Email not found!" in text
+
text = mgmt_get_text(
{"action": 'edit', "document": 'abcd', "body": 1234}, admin_cookies, 400)
assert "Email body" in text