diff options
| author | bwarsaw | 1999-01-09 05:13:00 +0000 |
|---|---|---|
| committer | bwarsaw | 1999-01-09 05:13:00 +0000 |
| commit | 3a96ce474c415706e47c6a8bb70faebb18dd591c (patch) | |
| tree | afddc1af30750ffe11f58e5489e65901b1e51be9 /Mailman/Utils.py | |
| parent | d6e0cc43c3ac987c88298b0a17e847eeea5db5d9 (diff) | |
| download | mailman-3a96ce474c415706e47c6a8bb70faebb18dd591c.tar.gz mailman-3a96ce474c415706e47c6a8bb70faebb18dd591c.tar.zst mailman-3a96ce474c415706e47c6a8bb70faebb18dd591c.zip | |
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.
Diffstat (limited to 'Mailman/Utils.py')
| -rw-r--r-- | Mailman/Utils.py | 26 |
1 files 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 <person@allusers.com> |
