You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2021/09/27 19:12:05 UTC
[incubator-ponymail-foal] 01/03: allow removing attachments from
disk and docs
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
commit 5fbaf625b78e7dcbe2a2dc485511a0b76d398c17
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Mon Sep 27 14:11:31 2021 -0500
allow removing attachments from disk and docs
---
server/endpoints/mgmt.py | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/server/endpoints/mgmt.py b/server/endpoints/mgmt.py
index b2ad597..062347a 100644
--- a/server/endpoints/mgmt.py
+++ b/server/endpoints/mgmt.py
@@ -101,6 +101,28 @@ async def process(
await plugins.auditlog.add_entry(session, action="unhide", target=doc, lid=lid, log=f"Unhid email {doc} from {lid} archives")
hidecount += 1
return aiohttp.web.Response(headers={}, status=200, text=f"Unhid {hidecount} emails from archives.")
+ # Removing an attachment
+ elif action == "delatt":
+ delcount = 0
+ for doc in docs:
+ assert isinstance(doc, str), "Attachment ID must be a string"
+ attachment = None
+ try:
+ assert session.database, "Database not connected!"
+ attachment = await session.database.get(
+ index=session.database.dbs.attachment, id=doc
+ )
+ except plugins.database.DBError:
+ pass # attachment not found
+
+ if attachment and isinstance(attachment, dict):
+ await session.database.delete(
+ index=session.database.dbs.attachment, id=attachment["_id"],
+ )
+ lid = "<system>"
+ await plugins.auditlog.add_entry(session, action="delatt", target=doc, lid=lid, log=f"Removed attachment {doc} from the archives")
+ delcount += 1
+ return aiohttp.web.Response(headers={}, status=200, text=f"Removed {delcount} attachments from archives.")
# Editing an email in place
elif action == "edit":
new_from = indata.get("from")
@@ -108,6 +130,7 @@ async def process(
new_list = indata.get("list", "")
private = indata.get("private", "no") == "yes"
new_body = indata.get("body", "")
+ attach_edit = indata.get("attachments", None)
# Check for consistency so we don't pollute the database
assert isinstance(doc, str) and doc, "Document ID is missing or invalid"
@@ -136,6 +159,8 @@ async def process(
email["list"] = lid
email["list_raw"] = lid
email["body"] = new_body
+ if attach_edit is not None: # Only set if truly editing attachments...
+ email["attachments"] = attach_edit
# Save edited email
await session.database.update(