mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-12 16:22:17 -05:00
Compiling email regex.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
@@ -19,7 +19,7 @@ TIME_FORMAT = "%Y-%m-%dT%H:%M:%S"
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
_phone_regex = re.compile("(?:\\+ *)?\\d[\\d\\- ]{7,}\\d")
|
_phone_regex = re.compile("(?:\\+ *)?\\d[\\d\\- ]{7,}\\d")
|
||||||
|
_email_regex = re.compile(r"[\w\.-]+@[\w\.-]+") # ['alice@google.com', 'bob@abc.com']
|
||||||
|
|
||||||
def _scrub(msg: Any) -> Any:
|
def _scrub(msg: Any) -> Any:
|
||||||
# Sometimes just an exception object is passed in for the message, skip those.
|
# Sometimes just an exception object is passed in for the message, skip those.
|
||||||
@@ -31,9 +31,7 @@ def _scrub(msg: Any) -> Any:
|
|||||||
for phone in phones:
|
for phone in phones:
|
||||||
msg = msg.replace(phone, "1XXXXXXXXXX")
|
msg = msg.replace(phone, "1XXXXXXXXXX")
|
||||||
|
|
||||||
emails = re.findall(
|
emails = _email_regex.findall(msg)
|
||||||
r"[\w\.-]+@[\w\.-]+", msg
|
|
||||||
) # ['alice@google.com', 'bob@abc.com']
|
|
||||||
for email in emails:
|
for email in emails:
|
||||||
# do something with each found email string
|
# do something with each found email string
|
||||||
masked_email = "XXXXX@XXXXXXX"
|
masked_email = "XXXXX@XXXXXXX"
|
||||||
|
|||||||
Reference in New Issue
Block a user