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 97d1ef8 Better parser and anonymiser
new 185efb6 Merge branch 'master' of
https://github.com/apache/incubator-ponymail-foal
97d1ef8 is described below
commit 97d1ef86050d1cad3b0c3d82c370857e728ee66a
Author: Sebb <[email protected]>
AuthorDate: Thu Nov 11 22:34:18 2021 +0000
Better parser and anonymiser
---
server/plugins/messages.py | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/server/plugins/messages.py b/server/plugins/messages.py
index a76cfbe..63704a6 100644
--- a/server/plugins/messages.py
+++ b/server/plugins/messages.py
@@ -87,11 +87,17 @@ def extract_name(addr):
addr = addr.strip("<>")
return [addr, addr]
-# Simple anonymiser; relies on @ appearing only in an email address
-def anonymize_mail_address(emaillist):
- return re.sub(
- r"(\S{1,2})\S*@([-a-zA-Z0-9_.]+)", "\\1...@\\2", emaillist
- )
+# anonymise a string of email entries
+def anonymize_mail_address(emailstring):
+ out = []
+ # split the email list into individual entries
+ for real, addr in email.utils.getaddresses([emailstring]):
+ # generate the anonymised entries
+ anon = re.sub(r"(\S{1,2})\S*@([-a-zA-Z0-9_.]+)", "\\1...@\\2", addr)
+ out.append(email.utils.formataddr([real, anon]))
+
+ # rejoin one per line
+ return ",\n ".join(out)
def anonymize(doc):
""" Anonymizes an email, hiding author email addresses."""