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/10 17:59:06 UTC
[incubator-ponymail-foal] 01/02: fix header issue,
expand to trim for external UI use
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 0dbce9d8d0e7e07aaf9039cc383ae4ed186812d2
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Thu Sep 10 19:58:31 2020 +0200
fix header issue, expand to trim for external UI use
---
server/plugins/mbox.py | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/server/plugins/mbox.py b/server/plugins/mbox.py
index 87f6fdb..dcfb066 100644
--- a/server/plugins/mbox.py
+++ b/server/plugins/mbox.py
@@ -41,13 +41,32 @@ PYPONY_RE_PREFIX = re.compile(r"^([a-zA-Z]+:\s*)+")
mbox_cache_privacy: typing.Dict[str, bool] = {}
-
-def trim_email(doc):
+used_ui_fields = [
+ "private",
+ "list",
+ "attachments",
+ "from",
+ "message-id",
+ "mid",
+ "body",
+ "epoch",
+ "subject",
+ "id",
+ "gravatar"
+]
+
+
+def trim_email(doc, external=False):
"""Trims away document fields not used by the UI"""
- for header in doc.keys():
+ for header in list(doc.keys()):
+ # Remove meta data fields which start with an underscore
if header.startswith('_'):
del doc[header]
+ # Remove other fields not used by the UI, if for external consumption
+ elif external and header not in used_ui_fields:
+ del doc[header]
+
def extract_name(addr):
""" Extract name and email from from: header """
@@ -481,3 +500,4 @@ def gravatar(eml):
mailaddr = email.utils.parseaddr(header_from)[1]
ghash = hashlib.md5(mailaddr.encode("utf-8")).hexdigest()
return ghash
+