------------------------------------------------------------
revno: 6687
committer: Barry Warsaw <[email protected]>
branch nick: cleanup
timestamp: Thu 2009-02-12 22:26:28 -0500
message:
  Remove Utils.ParseEmail() and Utils.midnight().
added:
  src/mailman/email/utils.py
modified:
  src/mailman/Utils.py
  src/mailman/bin/checkdbs.py
  src/mailman/mta/smtp_direct.py
  src/mailman/queue/bounce.py

=== modified file 'src/mailman/Utils.py'
--- src/mailman/Utils.py        2009-02-13 01:36:21 +0000
+++ src/mailman/Utils.py        2009-02-13 03:26:28 +0000
@@ -153,20 +153,6 @@
     return JOINER.join(text.split(SEP))
 
 
-# This takes an email address, and returns a tuple containing (user,host)
-def ParseEmail(email):
-    user = None
-    domain = None
-    email = email.lower()
-    at_sign = email.find('@')
-    if at_sign < 1:
-        return email, None
-    user = email[:at_sign]
-    rest = email[at_sign+1:]
-    domain = rest.split('.')
-    return user, domain
-
-
 def LCDomain(addr):
     "returns the address with the domain part lowercased"
     atind = addr.find('@')
@@ -185,7 +171,8 @@
         raise errors.InvalidEmailAddress(repr(s))
     if _badchars.search(s) or s[0] == '-':
         raise errors.InvalidEmailAddress(repr(s))
-    user, domain_parts = ParseEmail(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))
@@ -203,7 +190,8 @@
                                            '[email protected]']"""
 
     name = name.lower()
-    user, domain = ParseEmail(name)
+    from mailman.email.utils import split_email
+    user, domain = split_email(name)
     res = [name]
     if domain:
         domain = domain[1:]
@@ -486,16 +474,6 @@
 
 
 
-# Figure out epoch seconds of midnight at the start of today (or the given
-# 3-tuple date of (year, month, day).
-def midnight(date=None):
-    if date is None:
-        date = time.localtime()[:3]
-    # -1 for dst flag tells the library to figure it out
-    return time.mktime(date + (0,)*5 + (-1,))
-
-
-
 # The opposite of canonstr() -- sorta.  I.e. it attempts to encode s in the
 # charset of the given language, which is the character set that the page will
 # be rendered in, and failing that, replaces non-ASCII characters with their

=== modified file 'src/mailman/bin/checkdbs.py'
--- src/mailman/bin/checkdbs.py 2009-02-13 01:36:21 +0000
+++ src/mailman/bin/checkdbs.py 2009-02-13 03:26:28 +0000
@@ -140,6 +140,15 @@
 
 
 
+# Figure out epoch seconds of midnight at the start of today (or the given
+# 3-tuple date of (year, month, day).
+def midnight(date=None):
+    if date is None:
+        date = time.localtime()[:3]
+    # -1 for dst flag tells the library to figure it out
+    return time.mktime(date + (0,)*5 + (-1,))
+
+
 def main():
     opts, args, parser = parseargs()
     config.load(opts.config)
@@ -152,11 +161,11 @@
         try:
             count = config.db.requests.get_list_requests(mlist).count
             # While we're at it, let's evict yesterday's autoresponse data
-            midnight_today = Utils.midnight()
+            midnight_today = midnight()
             evictions = []
             for sender in mlist.hold_and_cmd_autoresponses.keys():
                 date, respcount = mlist.hold_and_cmd_autoresponses[sender]
-                if Utils.midnight(date) < midnight_today:
+                if midnight(date) < midnight_today:
                     evictions.append(sender)
             if evictions:
                 for sender in evictions:

=== added file 'src/mailman/email/utils.py'
--- src/mailman/email/utils.py  1970-01-01 00:00:00 +0000
+++ src/mailman/email/utils.py  2009-02-13 03:26:28 +0000
@@ -0,0 +1,41 @@
+# 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__ = [
+    'split_email',
+    ]
+
+
+def split_email(address):
+    """Split an email address into a user name and domain.
+
+    :param address: An email address.
+    :type address: string
+    :return: The user name and domain split on dots.
+    :rtype: 2-tuple where the first item is the local part and the second item
+        is a sequence of domain parts.
+    """
+    local_part, at, domain = address.partition('@')
+    if len(at) == 0:
+        # There was no at-sign in the email address.
+        return local_part, None
+    return local_part, domain.split('.')

=== modified file 'src/mailman/mta/smtp_direct.py'
--- src/mailman/mta/smtp_direct.py      2009-02-13 01:36:21 +0000
+++ src/mailman/mta/smtp_direct.py      2009-02-13 03:26:28 +0000
@@ -45,9 +45,9 @@
 from email.Utils import formataddr
 from zope.interface import implements
 
-from mailman.Utils import ParseEmail
 from mailman.config import config
 from mailman.core import errors
+from mailman.email.utils import split_email
 from mailman.i18n import _
 from mailman.interfaces.handler import IHandler
 from mailman.interfaces.mailinglist import Personalization
@@ -304,8 +304,8 @@
         handler.process(mlist, msgcopy, msgdata)
         # Calculate the envelope sender, which we may be VERPing
         if msgdata.get('verp'):
-            bmailbox, bdomain = ParseEmail(envsender)
-            rmailbox, rdomain = ParseEmail(recip)
+            bmailbox, bdomain = split_email(envsender)
+            rmailbox, rdomain = split_email(recip)
             if rdomain is None:
                 # The recipient address is not fully-qualified.  We can't
                 # deliver it to this person, nor can we craft a valid verp

=== modified file 'src/mailman/queue/bounce.py'
--- src/mailman/queue/bounce.py 2009-01-07 00:55:59 +0000
+++ src/mailman/queue/bounce.py 2009-02-13 03:26:28 +0000
@@ -26,9 +26,9 @@
 from email.Utils import parseaddr
 from lazr.config import as_timedelta
 
-from mailman import Utils
 from mailman.Bouncers import BouncerAPI
 from mailman.config import config
+from mailman.email.utils import split_email
 from mailman.i18n import _
 from mailman.queue import Runner
 
@@ -227,7 +227,7 @@
 
 
 def verp_bounce(mlist, msg):
-    bmailbox, bdomain = Utils.ParseEmail(mlist.GetBouncesEmail())
+    bmailbox, bdomain = split_email(mlist.GetBouncesEmail())
     # Sadly not every MTA bounces VERP messages correctly, or consistently.
     # Fall back to Delivered-To: (Postfix), Envelope-To: (Exim) and
     # Apparently-To:, and then short-circuit if we still don't have anything
@@ -258,7 +258,7 @@
 
 
 def verp_probe(mlist, msg):
-    bmailbox, bdomain = Utils.ParseEmail(mlist.GetBouncesEmail())
+    bmailbox, bdomain = split_email(mlist.GetBouncesEmail())
     # Sadly not every MTA bounces VERP messages correctly, or consistently.
     # Fall back to Delivered-To: (Postfix), Envelope-To: (Exim) and
     # Apparently-To:, and then short-circuit if we still don't have anything



--
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