This is an automated email from the ASF dual-hosted git repository.
humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
The following commit(s) were added to refs/heads/master by this push:
new 8cd5ce6 Fix an mgmt issue where source is one level too high up
8cd5ce6 is described below
commit 8cd5ce642b15fe24424a7e3c9761029974a86639
Author: Daniel Gruno <[email protected]>
AuthorDate: Mon Mar 29 20:16:44 2021 +0200
Fix an mgmt issue where source is one level too high up
---
server/endpoints/mgmt.py | 3 ++-
server/endpoints/source.py | 2 +-
server/plugins/mbox.py | 4 +++-
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/server/endpoints/mgmt.py b/server/endpoints/mgmt.py
index f7e91d4..808664a 100644
--- a/server/endpoints/mgmt.py
+++ b/server/endpoints/mgmt.py
@@ -87,8 +87,9 @@ async def process(
# Fetch source, mark as deleted (modified) and save
# We do this, as we can't edit the source easily, so we mark it as
off-limits instead.
- source = await plugins.mbox.get_source(session,
permalink=email["id"])
+ source = await plugins.mbox.get_source(session,
permalink=email["id"], raw=True)
if source:
+ source = source["_source"]
source["deleted"] = True
await session.database.index(
index=session.database.dbs.source, body=source,
id=email["id"],
diff --git a/server/endpoints/source.py b/server/endpoints/source.py
index f68bdb9..4050863 100644
--- a/server/endpoints/source.py
+++ b/server/endpoints/source.py
@@ -37,7 +37,7 @@ async def process(
if email and isinstance(email, dict) and not email.get("deleted"):
if plugins.aaa.can_access_email(session, email):
source = await plugins.mbox.get_source(session,
permalink=email["mid"])
- if source and not source.get("deleted"):
+ if source and not source["_source"].get("deleted"):
return aiohttp.web.Response(
headers={"Content-Type": "text/plain"}, status=200,
text=source["_source"]["source"],
)
diff --git a/server/plugins/mbox.py b/server/plugins/mbox.py
index 9e54f0a..a17f2a2 100644
--- a/server/plugins/mbox.py
+++ b/server/plugins/mbox.py
@@ -247,7 +247,7 @@ async def get_email(
return None
-async def get_source(session: plugins.session.SessionObject, permalink: str =
None):
+async def get_source(session: plugins.session.SessionObject, permalink: str =
None, raw=False):
assert session.database, "Database not connected!"
doctype = session.database.dbs.source
try:
@@ -263,6 +263,8 @@ async def get_source(session:
plugins.session.SessionObject, permalink: str = No
if len(res["hits"]["hits"]) == 1:
doc = res["hits"]["hits"][0]
doc["id"] = doc["_id"]
+ if raw:
+ return doc
# Check for base64-encoded source
if ":" not in doc["_source"]["source"]:
try: