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 2020/09/06 17:34:54 UTC

[incubator-ponymail-foal] 09/15: Add source endpoint

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 6a71ff0c7354c1419457c2bf6b7637a5924facd9
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sun Sep 6 19:21:18 2020 +0200

    Add source endpoint
---
 server/endpoints/source.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/server/endpoints/source.py b/server/endpoints/source.py
new file mode 100644
index 0000000..46d417c
--- /dev/null
+++ b/server/endpoints/source.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Simple endpoint that returns an email or an attachment from one"""
+
+import plugins.server
+import plugins.session
+import plugins.mbox
+import aiohttp.web
+import plugins.aaa
+
+
+async def process(
+    server: plugins.server.BaseServer,
+    session: plugins.session.SessionObject,
+    indata: dict,
+) -> aiohttp.web.Response:
+
+    email = await plugins.mbox.get_email(session, id=indata.get("id"))
+    if email and isinstance(email, dict):
+        if plugins.aaa.can_access_email(session, email):
+            source = await plugins.mbox.get_source(session, permalink=email["mid"])
+            if source:
+                return aiohttp.web.Response(
+                    headers={"Content-Type": "text/plain"},
+                    status=200,
+                    text=source["_source"]["source"],
+                )
+    return aiohttp.web.Response(headers={}, status=404, text="Email not found")
+
+
+def register(server: plugins.server.BaseServer):
+    return plugins.server.Endpoint(process)