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/09 09:18:54 UTC

[incubator-ponymail-foal] branch master updated (633ac74 -> 28d020e)

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git.


    from 633ac74  Don't use a set, it makes for random ordering. Stick with a list.
     new 22cc4cf  look for other permalinks if not found initially
     new 28d020e  refactor/simplify get_email

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 server/plugins/mbox.py | 50 ++++++++++++++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 18 deletions(-)


[incubator-ponymail-foal] 02/02: refactor/simplify get_email

Posted by hu...@apache.org.
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 28d020e72a2075e5074c289a8ff71eeef96192e1
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Wed Sep 9 11:18:39 2020 +0200

    refactor/simplify get_email
---
 server/plugins/mbox.py | 48 +++++++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 23 deletions(-)

diff --git a/server/plugins/mbox.py b/server/plugins/mbox.py
index 1610f1c..338d82f 100644
--- a/server/plugins/mbox.py
+++ b/server/plugins/mbox.py
@@ -159,14 +159,11 @@ async def get_email(
     # Older indexes may need a match instead of a strict terms agg in order to find
     # emails in DBs that may have been incorrectly analyzed.
     aggtype = "match"
+    doc = None
+    docs = None
     if permalink:
         try:
             doc = await session.database.get(index=doctype, id=permalink)
-            if doc and plugins.aaa.can_access_email(session, doc):
-                if not session.credentials:
-                    doc = anonymize(doc)
-                doc["_source"]["id"] = doc["_source"]["mid"]
-                return doc["_source"]
         # Email not found through primary ID, look for other permalinks?
         except plugins.database.DBError:
             res = await session.database.search(
@@ -175,12 +172,7 @@ async def get_email(
                 body={"query": {"bool": {"must": [{aggtype: {"permalinks": permalink}}]}}},
             )
             if len(res["hits"]["hits"]) == 1:
-                doc = res["hits"]["hits"][0]["_source"]
-                doc["id"] = doc["mid"]
-                if plugins.aaa.can_access_email(session, doc):
-                    if not session.credentials:
-                        doc = anonymize(doc)
-                    return doc
+                doc = res["hits"]["hits"][0]
     elif messageid:
         res = await session.database.search(
             index=doctype,
@@ -188,26 +180,36 @@ async def get_email(
             body={"query": {"bool": {"must": [{aggtype: {"message-id": messageid}}]}}},
         )
         if len(res["hits"]["hits"]) == 1:
-            doc = res["hits"]["hits"][0]["_source"]
-            doc["id"] = doc["mid"]
-            if plugins.aaa.can_access_email(session, doc):
-                if not session.credentials:
-                    doc = anonymize(doc)
-                return doc
+            doc = res["hits"]["hits"][0]
     elif irt:
         res = await session.database.search(
             index=doctype,
             size=250,
             body={"query": {"bool": {"must": [{aggtype: {"in-reply-to": irt}}]}}},
         )
-        docs = []
-        for doc in res["hits"]["hits"]:
-            if plugins.aaa.can_access_email(session, doc):
+        docs = res["hits"]["hits"]
+
+    # Did we find a single doc?
+    if doc and isinstance(doc, dict):
+        doc = doc['_source']
+        doc['id'] = doc['mid']
+        if doc and plugins.aaa.can_access_email(session, doc):
+            if not session.credentials:
+                doc = anonymize(doc)
+            return doc
+
+    # multi-doc return?
+    elif docs is not None and isinstance(docs, list):
+        docs_returned = []
+        for doc in docs:
+            doc = doc['_source']
+            doc['id'] = doc['mid']
+            if doc and plugins.aaa.can_access_email(session, doc):
                 if not session.credentials:
                     doc = anonymize(doc)
-                doc["_source"]["id"] = doc["_source"]["mid"]
-                docs.append(doc["_source"])
-        return docs
+                docs_returned.append(doc)
+        return docs_returned
+    # no doc?
     return None
 
 


[incubator-ponymail-foal] 01/02: look for other permalinks if not found initially

Posted by hu...@apache.org.
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 22cc4cf6130513ddc9e0c16e3b485cf1ac3265e6
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Wed Sep 9 11:08:56 2020 +0200

    look for other permalinks if not found initially
---
 server/plugins/mbox.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/server/plugins/mbox.py b/server/plugins/mbox.py
index 787c99a..1610f1c 100644
--- a/server/plugins/mbox.py
+++ b/server/plugins/mbox.py
@@ -167,8 +167,20 @@ async def get_email(
                     doc = anonymize(doc)
                 doc["_source"]["id"] = doc["_source"]["mid"]
                 return doc["_source"]
+        # Email not found through primary ID, look for other permalinks?
         except plugins.database.DBError:
-            pass
+            res = await session.database.search(
+                index=doctype,
+                size=1,
+                body={"query": {"bool": {"must": [{aggtype: {"permalinks": permalink}}]}}},
+            )
+            if len(res["hits"]["hits"]) == 1:
+                doc = res["hits"]["hits"][0]["_source"]
+                doc["id"] = doc["mid"]
+                if plugins.aaa.can_access_email(session, doc):
+                    if not session.credentials:
+                        doc = anonymize(doc)
+                    return doc
     elif messageid:
         res = await session.database.search(
             index=doctype,