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 2021/10/16 18:14:53 UTC

[incubator-ponymail-foal] branch master updated: also handle un-encased email addresses in anonymizing

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


The following commit(s) were added to refs/heads/master by this push:
     new 0ca4f9c  also handle un-encased email addresses in anonymizing
0ca4f9c is described below

commit 0ca4f9cd38da2121afc67f4e258a81c480aa37a6
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sat Oct 16 20:14:45 2021 +0200

    also handle un-encased email addresses in anonymizing
---
 server/plugins/messages.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/server/plugins/messages.py b/server/plugins/messages.py
index 88e3558..b705962 100644
--- a/server/plugins/messages.py
+++ b/server/plugins/messages.py
@@ -95,9 +95,14 @@ def anonymize(doc):
         ptr["md5"] = hashlib.md5(
             bytes(fremail.lower(), encoding="ascii", errors="replace")
         ).hexdigest()
-        ptr["from"] = re.sub(
-            r"<(\S{1,2})\S*@([-a-zA-Z0-9_.]+)>", "<\\1...@\\2>", ptr["from"]
-        )
+        if not all(b in ptr["from"] for b in ['<', '>']):  # no <> encasing?
+            ptr["from"] = re.sub(
+                r"(\S{1,2})\S*@([-a-zA-Z0-9_.]+)", "\\1...@\\2", ptr["from"]
+            )
+        else:  # standard <> encasing
+            ptr["from"] = re.sub(
+                r"<(\S{1,2})\S*@([-a-zA-Z0-9_.]+)>", "<\\1...@\\2>", ptr["from"]
+            )
         if ptr["body"]:
             ptr["body"] = re.sub(
                 r"<(\S{1,2})\S*@([-a-zA-Z0-9_.]+)>", "<\\1...@\\2>", ptr["body"]