This is an automated email from the ASF dual-hosted git repository.
sebb 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 b8347c4 Don't try to recalculate the gravatar
b8347c4 is described below
commit b8347c4db6201adf43983bac05315f05ad6d9d1b
Author: Sebb <[email protected]>
AuthorDate: Sun Nov 14 11:52:49 2021 +0000
Don't try to recalculate the gravatar
At this point, the email address will have been anonymised.
---
server/endpoints/stats.py | 8 +++++---
server/plugins/messages.py | 7 ++++---
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/server/endpoints/stats.py b/server/endpoints/stats.py
index 481367e..c243aaf 100644
--- a/server/endpoints/stats.py
+++ b/server/endpoints/stats.py
@@ -70,12 +70,14 @@ async def process(
threads = plugins.messages.ThreadConstructor(results)
tstruct, authors = await server.runners.run(threads.construct)
- all_authors = sorted(authors.items(), key=lambda x: x[1],
reverse=True) # sort in reverse by author count
+ # author entries are now [count, gravatar]
+ # as we cannot reconstruct the correct gravatar from an anonymised
address
+ all_authors = sorted(authors.items(), key=lambda x: x[0][1],
reverse=True) # sort in reverse by author count
top10_authors = []
- for author, count in all_authors[:10]:
+ for author, data in all_authors[:10]:
name, address = email.utils.parseaddr(author)
top10_authors.append(
- {"email": address, "name": name, "count": count, "gravatar":
plugins.messages.gravatar(author),}
+ {"email": address, "name": name, "count": data[0], "gravatar":
data[1],}
)
# Trim email data so as to reduce download sizes
diff --git a/server/plugins/messages.py b/server/plugins/messages.py
index 8a796f9..b99feb8 100644
--- a/server/plugins/messages.py
+++ b/server/plugins/messages.py
@@ -536,7 +536,8 @@ class ThreadConstructor:
def __init__(self, emails: typing.List[typing.Dict]):
self.emails = emails
self.threads: typing.List[dict] = []
- self.authors: typing.Dict[str, int] = {}
+ # this now includes the gravatar, to avoid issues with address
anonymisation
+ self.authors: typing.Dict[str, list] = {}
self.hashed_by_msg_id: typing.Dict[str, dict] = {}
self.hashed_by_subject: typing.Dict[str, dict] = {}
@@ -545,8 +546,8 @@ class ThreadConstructor:
for cur_email in sorted(self.emails, key=lambda x: x["epoch"]):
author = cur_email.get("from")
if author not in self.authors:
- self.authors[author] = 0
- self.authors[author] += 1
+ self.authors[author] = [0, cur_email.get("gravatar")]
+ self.authors[author][0] += 1
subject = cur_email.get("subject", "").replace(
"\n", ""
) # Crop multi-line subjects