summaryrefslogtreecommitdiff
path: root/src/mailman/email/validate.py
diff options
context:
space:
mode:
authorMark Sapiro2016-07-18 21:28:07 -0700
committerMark Sapiro2016-07-18 21:28:07 -0700
commit1ff113e928edff617188cb06fe1d27a142a7765c (patch)
tree9fa4998ecb112d4eba611e9ea7867c6b4c82f461 /src/mailman/email/validate.py
parenta3e6f5952f262557d7279cad372d2f4f532d9b36 (diff)
downloadmailman-1ff113e928edff617188cb06fe1d27a142a7765c.tar.gz
mailman-1ff113e928edff617188cb06fe1d27a142a7765c.tar.zst
mailman-1ff113e928edff617188cb06fe1d27a142a7765c.zip
Improved email address validation and added tests.
Diffstat (limited to 'src/mailman/email/validate.py')
-rw-r--r--src/mailman/email/validate.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/mailman/email/validate.py b/src/mailman/email/validate.py
index 3d80b3a51..99371d9e5 100644
--- a/src/mailman/email/validate.py
+++ b/src/mailman/email/validate.py
@@ -26,10 +26,11 @@ from mailman.utilities.email import split_email
from zope.interface import implementer
-# What other characters should be disallowed?
-_badchars = re.compile(r'[][()<>|:;^,\\"\000-\037\177-\377]')
-# Strictly speaking, some of the above are allowed in quoted local parts, but
-# this can open the door to certain web exploits so we don't allow them.
+# What other characters should be allowed?
+_valid_local = re.compile("[-0-9a-z!#$%&'*+./=?@_`{}~]", re.IGNORECASE)
+# Strictly speaking, both ^ and | are allowed and others are allowed in quoted
+# local parts, but this can open the door to certain web exploits so we don't
+# allow them.
_valid_domain = re.compile('[-a-z0-9]', re.IGNORECASE)
# These are the only characters allowed in domain parts.
@@ -41,11 +42,11 @@ class Validator:
def is_valid(self, email):
"""See `IEmailValidator`."""
- if not email or ' ' in email:
- return False
- if _badchars.search(email):
+ if not email:
return False
user, domain_parts = split_email(email)
+ if not user or len(_valid_local.sub('', user)) > 0:
+ return False
# Local, unqualified addresses are not allowed.
if not domain_parts:
return False