------------------------------------------------------------
revno: 6688
committer: Barry Warsaw <[email protected]>
branch nick: cleanup
timestamp: Thu 2009-02-12 22:52:18 -0500
message:
  Remove or move QuotePeriods(), LCDomain(), and ValidateEmail from the Utils
  module.
added:
  src/mailman/email/validate.py
modified:
  src/mailman/Utils.py
  src/mailman/app/lifecycle.py
  src/mailman/app/membership.py
  src/mailman/app/registrar.py
  src/mailman/bin/list_members.py
  src/mailman/core/errors.py

=== modified file 'src/mailman/Utils.py'
--- src/mailman/Utils.py        2009-02-13 03:26:28 +0000
+++ src/mailman/Utils.py        2009-02-13 03:52:18 +0000
@@ -147,40 +147,6 @@
 
 
 
-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.

=== modified file 'src/mailman/app/lifecycle.py'
--- src/mailman/app/lifecycle.py        2009-01-21 01:54:22 +0000
+++ src/mailman/app/lifecycle.py        2009-02-13 03:52:18 +0000
@@ -32,9 +32,9 @@
 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 @@
     """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)

=== modified file 'src/mailman/app/membership.py'
--- src/mailman/app/membership.py       2009-02-10 03:19:18 +0000
+++ src/mailman/app/membership.py       2009-02-13 03:52:18 +0000
@@ -34,6 +34,7 @@
 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 @@
     :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)

=== modified file 'src/mailman/app/registrar.py'
--- src/mailman/app/registrar.py        2009-02-10 03:19:18 +0000
+++ src/mailman/app/registrar.py        2009-02-13 03:52:18 +0000
@@ -31,9 +31,9 @@
 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 @@
         """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,

=== modified file 'src/mailman/bin/list_members.py'
--- src/mailman/bin/list_members.py     2009-01-05 00:41:05 +0000
+++ src/mailman/bin/list_members.py     2009-02-13 03:52:18 +0000
@@ -19,9 +19,9 @@
 
 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 @@
     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 @@
         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:

=== modified file 'src/mailman/core/errors.py'
--- src/mailman/core/errors.py  2009-01-17 02:04:21 +0000
+++ src/mailman/core/errors.py  2009-02-13 03:52:18 +0000
@@ -78,7 +78,7 @@
 
 
 # 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."""
 

=== added file 'src/mailman/email/validate.py'
--- src/mailman/email/validate.py       1970-01-01 00:00:00 +0000
+++ src/mailman/email/validate.py       2009-02-13 03:52:18 +0000
@@ -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



--
Primary development focus
https://code.launchpad.net/~mailman-coders/mailman/3.0

Your team Mailman Checkins is subscribed to branch lp:mailman.
To unsubscribe from this branch go to 
https://code.launchpad.net/~mailman-coders/mailman/3.0/+edit-subscription.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe: 
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to