summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2009-02-12 22:26:28 -0500
committerBarry Warsaw2009-02-12 22:26:28 -0500
commit8b8586ca375b23787b5a74761773cd759f74994e (patch)
tree13b74a80eb132184a763e3148392b0a9d80fd086
parent62f4c909f90535986614a411db982bdcccaec3a1 (diff)
downloadmailman-8b8586ca375b23787b5a74761773cd759f74994e.tar.gz
mailman-8b8586ca375b23787b5a74761773cd759f74994e.tar.zst
mailman-8b8586ca375b23787b5a74761773cd759f74994e.zip
-rw-r--r--src/mailman/Utils.py30
-rw-r--r--src/mailman/bin/checkdbs.py13
-rw-r--r--src/mailman/email/utils.py41
-rw-r--r--src/mailman/mta/smtp_direct.py6
-rw-r--r--src/mailman/queue/bounce.py6
5 files changed, 62 insertions, 34 deletions
diff --git a/src/mailman/Utils.py b/src/mailman/Utils.py
index 866fa89ad..023da728f 100644
--- a/src/mailman/Utils.py
+++ b/src/mailman/Utils.py
@@ -153,20 +153,6 @@ def QuotePeriods(text):
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 @@ def ValidateEmail(s):
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 @@ def GetPossibleMatchingAddrs(name):
'scott@pobox.com']"""
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 @@ def maketext(templatefile, dict=None, raw=False, lang=None, mlist=None):
-# 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
diff --git a/src/mailman/bin/checkdbs.py b/src/mailman/bin/checkdbs.py
index 10d34aa22..c9789287b 100644
--- a/src/mailman/bin/checkdbs.py
+++ b/src/mailman/bin/checkdbs.py
@@ -140,6 +140,15 @@ def auto_discard(mlist):
+# 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 @@ def main():
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:
diff --git a/src/mailman/email/utils.py b/src/mailman/email/utils.py
new file mode 100644
index 000000000..56c11f77c
--- /dev/null
+++ b/src/mailman/email/utils.py
@@ -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('.')
diff --git a/src/mailman/mta/smtp_direct.py b/src/mailman/mta/smtp_direct.py
index d45bf15d6..b1011c904 100644
--- a/src/mailman/mta/smtp_direct.py
+++ b/src/mailman/mta/smtp_direct.py
@@ -45,9 +45,9 @@ from email.Header import Header
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 @@ def verpdeliver(mlist, msg, msgdata, envsender, failures, conn):
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
diff --git a/src/mailman/queue/bounce.py b/src/mailman/queue/bounce.py
index ced731d6d..c966729bb 100644
--- a/src/mailman/queue/bounce.py
+++ b/src/mailman/queue/bounce.py
@@ -26,9 +26,9 @@ import datetime
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 @@ class BounceRunner(Runner, BounceMixin):
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_bounce(mlist, msg):
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