From 5085e5d09086766e2b3a55f6d9e2f797015f25d0 Mon Sep 17 00:00:00 2001 From: Bobby Date: Sat, 10 Sep 2022 20:29:09 -0400 Subject: Added email_rfc_5322 pattern --- src/edify/library/__init__.py | 1 + src/edify/library/mail.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'src') diff --git a/src/edify/library/__init__.py b/src/edify/library/__init__.py index 5411d36..e77c7f6 100644 --- a/src/edify/library/__init__.py +++ b/src/edify/library/__init__.py @@ -2,4 +2,5 @@ # Import everything from the library. from .mail import email +from .mail import email_rfc_5322 from .phone import phone_number diff --git a/src/edify/library/mail.py b/src/edify/library/mail.py index ecb0cf2..02f9484 100644 --- a/src/edify/library/mail.py +++ b/src/edify/library/mail.py @@ -1,6 +1,7 @@ import re pattern = r"^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$" # noqa +rfc_5322_pattern = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])" # noqa def email(email: str) -> bool: @@ -16,3 +17,18 @@ def email(email: str) -> bool: return True else: return False + + +def email_rfc_5322(email: str) -> bool: + """Checks if a string is a valid email address. + + Args: + email (str): The string to check. + Returns: + bool: True if the string is a valid email address, False otherwise. + """ + + if re.match(rfc_5322_pattern, email): + return True + else: + return False -- cgit v1.2.3