From 3a96ce474c415706e47c6a8bb70faebb18dd591c Mon Sep 17 00:00:00 2001 From: bwarsaw Date: Sat, 9 Jan 1999 05:13:00 +0000 Subject: ValidateEmail(): Renamed from ValidEmail(). Cleaned up its interface so that it always raises an exception if an address problem is uncovered (it used to both raise exceptions and return 0 or 1). It now has no useful return value. Added a re to barf on other unacceptable characters in an email address, currently: [ ] ( ) < > | ; Should there be others? The test that were there are retained, but the domain_parts test was cleaned up (there was a redundant test in there). Note that now unqualified addresses (e.g. those that don't contain an `@' are now DISALLOWED). This goes partially toward Greg Stein's suggestion. --- Mailman/Utils.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Mailman/Utils.py b/Mailman/Utils.py index 3cc6c35e5..09e1bd724 100644 --- a/Mailman/Utils.py +++ b/Mailman/Utils.py @@ -229,24 +229,24 @@ def QuotePeriods(text): return string.join(string.split(text, '\n.\n'), '\n .\n') -def ValidEmail(str): +# TBD: what other characters should be disallowed? +_badchars = re.compile('[][()<>|;]') + +def ValidateEmail(str): """Verify that the an email address isn't grossly invalid.""" # Pretty minimal, cheesy check. We could do better... - if ((string.find(str, '|') <> -1) or (string.find(str, ';') <> -1) - or str[0] == '-'): - raise Errors.MMHostileAddress - if string.find(str, '/') <> -1: - if os.path.isdir(os.path.split(str)[0]): - raise Errors.MMHostileAddress + if _badchars.search(str) or str[0] == '-': + raise Errors.MMHostileAddress + if string.find(str, '/') <> -1 and \ + os.path.isdir(os.path.split(str)[0]): + # then + raise Errors.MMHostileAddress user, domain_parts = ParseEmail(str) + # this means local, unqualified addresses, are no allowed if not domain_parts: - if string.find(str, '@') < 1: - return 0 - else: - return 1 + raise Errors.MMBadEmailError if len(domain_parts) < 2: - return 0 - return 1 + raise Errors.MMBadEmailError # User J. Person -- cgit v1.3.1