summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarry Warsaw2009-02-12 22:52:18 -0500
committerBarry Warsaw2009-02-12 22:52:18 -0500
commit8d43a75b5c7a278bbf9f5bd5143bee4b2925f3b1 (patch)
tree49538d15e71f0b520758f6e2f189aa5f143baaa3 /src
parent8b8586ca375b23787b5a74761773cd759f74994e (diff)
downloadmailman-8d43a75b5c7a278bbf9f5bd5143bee4b2925f3b1.tar.gz
mailman-8d43a75b5c7a278bbf9f5bd5143bee4b2925f3b1.tar.zst
mailman-8d43a75b5c7a278bbf9f5bd5143bee4b2925f3b1.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/Utils.py34
-rw-r--r--src/mailman/app/lifecycle.py4
-rw-r--r--src/mailman/app/membership.py3
-rw-r--r--src/mailman/app/registrar.py4
-rw-r--r--src/mailman/bin/list_members.py12
-rw-r--r--src/mailman/core/errors.py2
-rw-r--r--src/mailman/email/validate.py70
7 files changed, 79 insertions, 50 deletions
diff --git a/src/mailman/Utils.py b/src/mailman/Utils.py
index 023da728f..05da4c1d5 100644
--- a/src/mailman/Utils.py
+++ b/src/mailman/Utils.py
@@ -147,40 +147,6 @@ def wrap(text, column=70, honor_leading_ws=True):
-def QuotePeriods(text):
- JOINER = '\n .\n'
- SEP = '\n.\n'
- return JOINER.join(text.split(SEP))
-
-
-def LCDomain(addr):
- "returns the address with the domain part lowercased"
- atind = addr.find('@')
- if atind == -1: # no domain part
- return addr
- return addr[:atind] + '@' + addr[atind+1:].lower()
-
-
-# TBD: what other characters should be disallowed?
-_badchars = re.compile(r'[][()<>|;^,\000-\037\177-\377]')
-
-def ValidateEmail(s):
- """Verify that the an email address isn't grossly evil."""
- # Pretty minimal, cheesy check. We could do better...
- if not s or ' ' in s:
- raise errors.InvalidEmailAddress(repr(s))
- if _badchars.search(s) or s[0] == '-':
- raise errors.InvalidEmailAddress(repr(s))
- from mailman.email.utils import split_email
- user, domain_parts = split_email(s)
- # Local, unqualified addresses are not allowed.
- if not domain_parts:
- raise errors.InvalidEmailAddress(repr(s))
- if len(domain_parts) < 2:
- raise errors.InvalidEmailAddress(repr(s))
-
-
-
def GetPossibleMatchingAddrs(name):
"""returns a sorted list of addresses that could possibly match
a given name.
diff --git a/src/mailman/app/lifecycle.py b/src/mailman/app/lifecycle.py
index eec00dc86..5dfc0862d 100644
--- a/src/mailman/app/lifecycle.py
+++ b/src/mailman/app/lifecycle.py
@@ -32,9 +32,9 @@ import shutil
import logging
from mailman import Utils
-from mailman.Utils import ValidateEmail
from mailman.config import config
from mailman.core import errors
+from mailman.email.validate import validate
from mailman.interfaces.member import MemberRole
@@ -46,7 +46,7 @@ def create_list(fqdn_listname, owners=None):
"""Create the named list and apply styles."""
if owners is None:
owners = []
- ValidateEmail(fqdn_listname)
+ validate(fqdn_listname)
listname, domain = fqdn_listname.split('@', 1)
if domain not in config.domains:
raise errors.BadDomainSpecificationError(domain)
diff --git a/src/mailman/app/membership.py b/src/mailman/app/membership.py
index 79e2501bd..6681cdda3 100644
--- a/src/mailman/app/membership.py
+++ b/src/mailman/app/membership.py
@@ -34,6 +34,7 @@ from mailman.app.notifications import send_goodbye_message
from mailman.config import config
from mailman.core import errors
from mailman.email.message import Message, OwnerNotification
+from mailman.email.validate import validate
from mailman.interfaces.member import AlreadySubscribedError, MemberRole
_ = i18n._
@@ -60,7 +61,7 @@ def add_member(mlist, address, realname, password, delivery_mode, language):
:type language: string
"""
# Let's be extra cautious.
- Utils.ValidateEmail(address)
+ validate(address)
if mlist.members.get_member(address) is not None:
raise AlreadySubscribedError(
mlist.fqdn_listname, address, MemberRole.member)
diff --git a/src/mailman/app/registrar.py b/src/mailman/app/registrar.py
index 654106668..0cd43d484 100644
--- a/src/mailman/app/registrar.py
+++ b/src/mailman/app/registrar.py
@@ -31,9 +31,9 @@ import datetime
from pkg_resources import resource_string
from zope.interface import implements
-from mailman.Utils import ValidateEmail
from mailman.config import config
from mailman.email.message import UserNotification
+from mailman.email.validate import validate
from mailman.i18n import _
from mailman.interfaces.domain import IDomain
from mailman.interfaces.member import MemberRole
@@ -58,7 +58,7 @@ class Registrar:
"""See `IUserRegistrar`."""
# First, do validation on the email address. If the address is
# invalid, it will raise an exception, otherwise it just returns.
- ValidateEmail(address)
+ validate(address)
# Create a pendable for the registration.
pendable = PendableRegistration(
type=PendableRegistration.PEND_KEY,
diff --git a/src/mailman/bin/list_members.py b/src/mailman/bin/list_members.py
index 443f764d6..4ba0a95db 100644
--- a/src/mailman/bin/list_members.py
+++ b/src/mailman/bin/list_members.py
@@ -19,9 +19,9 @@ import sys
from email.Utils import formataddr
-from mailman import Utils
from mailman.config import config
from mailman.core import errors
+from mailman.email.validate import is_valid
from mailman.i18n import _
from mailman.interfaces import DeliveryStatus
from mailman.options import SingleMailingListOptions
@@ -116,14 +116,6 @@ def safe(string):
return string.encode(sys.getdefaultencoding(), 'replace')
-def isinvalid(addr):
- try:
- Utils.ValidateEmail(addr)
- return False
- except errors.EmailAddressError:
- return True
-
-
def whymatches(mlist, addr, why):
# Return true if the `why' matches the reason the address is enabled, or
@@ -164,7 +156,7 @@ def main():
for address in all:
user = config.db.user_manager.get_user(address)
name = (user.real_name if fullnames and user else u'')
- if options.options.invalid and isinvalid(address):
+ if options.options.invalid and not is_valid(address):
print >> fp, formataddr((safe(name), address))
return
if options.options.regular:
diff --git a/src/mailman/core/errors.py b/src/mailman/core/errors.py
index 39401127e..9b053301c 100644
--- a/src/mailman/core/errors.py
+++ b/src/mailman/core/errors.py
@@ -78,7 +78,7 @@ class BadDomainSpecificationError(MailmanError):
# Exception hierarchy for bad email address errors that can be raised from
-# Utils.ValidateEmail()
+# mailman.email.validate.validate()
class EmailAddressError(MailmanError):
"""Base class for email address validation errors."""
diff --git a/src/mailman/email/validate.py b/src/mailman/email/validate.py
new file mode 100644
index 000000000..fc33b1509
--- /dev/null
+++ b/src/mailman/email/validate.py
@@ -0,0 +1,70 @@
+# Copyright (C) 2009 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Module stuff."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'is_valid',
+ 'validate',
+ ]
+
+
+import re
+
+from mailman.core.errors import InvalidEmailAddress
+from mailman.email.utils import split_email
+
+
+# What other characters should be disallowed?
+_badchars = re.compile(r'[][()<>|;^,\000-\037\177-\377]')
+
+
+
+def validate(address):
+ """Validate an email address.
+
+ :param address: An email address.
+ :type address: string
+ :raise `InvalidEmailAddress`: when the address is deemed invalid.
+ """
+ if not is_valid(address):
+ raise InvalidEmailAddress(repr(address))
+
+
+
+def is_valid(address):
+ """Check if an email address if valid.
+
+ :param address: An email address.
+ :type address: string
+ :return: A flag indicating whether the email address is okay or not.
+ :rtype: bool
+ """
+ if not address or ' ' in address:
+ return False
+ if _badchars.search(address) or address[0] == '-':
+ return False
+ user, domain_parts = split_email(address)
+ # Local, unqualified addresses are not allowed.
+ if not domain_parts:
+ return False
+ if len(domain_parts) < 2:
+ return False
+ return True