aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-09-10 20:29:09 -0400
committerBobby <[email protected]>2022-09-10 20:29:09 -0400
commit5085e5d09086766e2b3a55f6d9e2f797015f25d0 (patch)
tree7bc5f0dff1384867cf4d58efcc872543119bf727 /src
parent6361141215b89942105203f91d34a2794d89a295 (diff)
downloadedify-5085e5d09086766e2b3a55f6d9e2f797015f25d0.tar.xz
edify-5085e5d09086766e2b3a55f6d9e2f797015f25d0.zip
Added email_rfc_5322 pattern
Diffstat (limited to 'src')
-rw-r--r--src/edify/library/__init__.py1
-rw-r--r--src/edify/library/mail.py16
2 files changed, 17 insertions, 0 deletions
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