diff options
| -rw-r--r-- | contrib/fblast.py (renamed from tests/fblast.py) | 0 | ||||
| -rw-r--r-- | src/mailman/Bouncers/BouncerAPI.py | 64 | ||||
| -rw-r--r-- | src/mailman/app/bounces.py | 15 | ||||
| -rw-r--r-- | src/mailman/app/finder.py | 3 | ||||
| -rw-r--r-- | src/mailman/queue/bounce.py | 11 | ||||
| -rw-r--r-- | src/mailman/tests/test_bounces.py | 3 | ||||
| -rw-r--r-- | tests/msgs/bad_01.txt | 62 |
7 files changed, 24 insertions, 134 deletions
diff --git a/tests/fblast.py b/contrib/fblast.py index 50368b3be..50368b3be 100644 --- a/tests/fblast.py +++ b/contrib/fblast.py diff --git a/src/mailman/Bouncers/BouncerAPI.py b/src/mailman/Bouncers/BouncerAPI.py deleted file mode 100644 index 6f52f2a3f..000000000 --- a/src/mailman/Bouncers/BouncerAPI.py +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright (C) 1998-2010 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/>. - -"""Contains all the common functionality for msg bounce scanning API. - -This module can also be used as the basis for a bounce detection testing -framework. When run as a script, it expects two arguments, the listname and -the filename containing the bounce message. -""" - -import sys - -# If a bounce detector returns Stop, that means to just discard the message. -# An example is warning messages for temporary delivery problems. These -# shouldn't trigger a bounce notification, but we also don't want to send them -# on to the list administrator. -Stop = object() - - -BOUNCE_PIPELINE = [ - 'DSN', - 'Qmail', - 'Postfix', - 'Yahoo', - 'Caiwireless', - 'Exchange', - 'Exim', - 'Netscape', - 'Compuserve', - 'Microsoft', - 'GroupWise', - 'SMTP32', - 'SimpleMatch', - 'SimpleWarning', - 'Yale', - 'LLNL', - ] - - - -# msg must be a mimetools.Message -def ScanMessages(mlist, msg): - for module in BOUNCE_PIPELINE: - modname = 'mailman.Bouncers.' + module - __import__(modname) - addrs = sys.modules[modname].process(msg) - if addrs: - # Return addrs even if it is Stop. BounceRunner needs this info. - return addrs - return [] diff --git a/src/mailman/app/bounces.py b/src/mailman/app/bounces.py index 9d7ea0a74..890e040d0 100644 --- a/src/mailman/app/bounces.py +++ b/src/mailman/app/bounces.py @@ -22,6 +22,7 @@ from __future__ import absolute_import, unicode_literals __metaclass__ = type __all__ = [ 'bounce_message', + 'scan_message', ] import logging @@ -30,8 +31,10 @@ from email.mime.message import MIMEMessage from email.mime.text import MIMEText from mailman.Utils import oneline +from mailman.app.finder import find_components from mailman.core.i18n import _ from mailman.email.message import UserNotification +from mailman.interfaces.bounce import IBounceDetector log = logging.getLogger('mailman.config') @@ -69,3 +72,15 @@ def bounce_message(mlist, msg, e=None): bmsg.attach(txt) bmsg.attach(MIMEMessage(msg)) bmsg.send(mlist) + + + +def scan_message(mlist, msg): + """Scan all the message for heuristically determined bounce addresses.""" + for detector_class in find_components('mailman.bouncers', IBounceDetector): + addresses = detector().process(msg) + # Detectors may return None or an empty sequence to signify that no + # addresses have been found. + if addresses: + return addresses + return [] diff --git a/src/mailman/app/finder.py b/src/mailman/app/finder.py index f6101fcaa..d4b634940 100644 --- a/src/mailman/app/finder.py +++ b/src/mailman/app/finder.py @@ -42,8 +42,9 @@ def find_components(package, interface): :type package: string :param interface: The interface that returned objects must conform to. :type interface: `Interface` + :return: The sequence of matching components. + :rtype: objects implementing `interface` """ - # Find all rules found in all modules inside our package. for filename in resource_listdir(package, ''): basename, extension = os.path.splitext(filename) if extension != '.py': diff --git a/src/mailman/queue/bounce.py b/src/mailman/queue/bounce.py index 5b705a5c7..2a7af6d1a 100644 --- a/src/mailman/queue/bounce.py +++ b/src/mailman/queue/bounce.py @@ -26,10 +26,11 @@ import datetime from email.Utils import parseaddr from lazr.config import as_timedelta -from mailman.Bouncers import BouncerAPI +from mailman.app.bounce import scan_message from mailman.config import config from mailman.core.i18n import _ from mailman.email.utils import split_email +from mailman.interfaces.bounce import Stop from mailman.queue import Runner @@ -192,7 +193,7 @@ class BounceRunner(Runner, BounceMixin): addrs = verp_bounce(mlist, msg) if addrs: # We have an address, but check if the message is non-fatal. - if BouncerAPI.ScanMessages(mlist, msg) is BouncerAPI.Stop: + if scan_messages(mlist, msg) is Stop: return else: # See if this was a probe message. @@ -202,8 +203,8 @@ class BounceRunner(Runner, BounceMixin): return # That didn't give us anything useful, so try the old fashion # bounce matching modules. - addrs = BouncerAPI.ScanMessages(mlist, msg) - if addrs is BouncerAPI.Stop: + addrs = scan_messages(mlist, msg) + if addrs is Stop: # This is a recognized, non-fatal notice. Ignore it. return # If that still didn't return us any useful addresses, then send it on @@ -214,7 +215,7 @@ class BounceRunner(Runner, BounceMixin): maybe_forward(mlist, msg) return # BAW: It's possible that there are None's in the list of addresses, - # although I'm unsure how that could happen. Possibly ScanMessages() + # although I'm unsure how that could happen. Possibly scan_messages() # can let None's sneak through. In any event, this will kill them. addrs = filter(None, addrs) self._queue_bounces(mlist.fqdn_listname, addrs, msg) diff --git a/src/mailman/tests/test_bounces.py b/src/mailman/tests/test_bounces.py index 90387315f..ac52d077c 100644 --- a/src/mailman/tests/test_bounces.py +++ b/src/mailman/tests/test_bounces.py @@ -173,9 +173,8 @@ class BounceTest(unittest.TestCase): def test_bounce(self): for modname, filename, addrs in self.DATA: - module = 'mailman.Bouncers.' + modname + module = 'mailman.bouncers.' + modname __import__(module) - # XXX Convert this tousing package resources msg = self._getmsg(filename) foundaddrs = sys.modules[module].process(msg) # Some modules return None instead of [] for failure diff --git a/tests/msgs/bad_01.txt b/tests/msgs/bad_01.txt deleted file mode 100644 index 04a172677..000000000 --- a/tests/msgs/bad_01.txt +++ /dev/null @@ -1,62 +0,0 @@ -From xxxxx@webmail6.catholic.org Mon Oct 2 22:11:14 2000 -Return-Path: <xxxxx@webmail6.catholic.org> -Delivered-To: mailman-developers@python.org -Received: from webmail6.catholic.org (unknown [63.196.163.10]) - by dinsdale.python.org (Postfix) with ESMTP id 680521CF4C - for <mailman-developers@python.org>; Mon, 2 Oct 2000 22:11:14 -0400 (EDT) -Received: (from root@localhost) - by webmail6.catholic.org (8.10.1/8.10.1) id e932BDE08525; - Mon, 2 Oct 2000 19:11:13 -0700 (PDT) -To: "catholic.org@catholicnet.org.uk" <@@forward@@.python.org> -Received: from dinsdale.python.org (dinsdale.cnri.reston.va.us [132.151.1.21]) - by webmail6.catholic.org (8.10.1/8.10.1) with SMTP id e932BBa08476 - for <xxxxx@catholic.org>; Mon, 2 Oct 2000 19:11:11 -0700 (PDT) -Received: from dinsdale.python.org (localhost [127.0.0.1]) - by dinsdale.python.org (Postfix) with ESMTP - id 1DF9A1CF35; Mon, 2 Oct 2000 22:11:07 -0400 (EDT) -Delivered-To: mailman-users@python.org -Received: from alb-net.com (www.alb-net.com [205.216.244.65]) - by dinsdale.python.org (Postfix) with ESMTP - id 55FEC1CF28; Mon, 2 Oct 2000 22:10:11 -0400 (EDT) -Received: from localhost (localhost [127.0.0.1]) - by alb-net.com (8.11.0/8.11.0) with ESMTP id e932AAU22315; - Mon, 2 Oct 2000 22:10:10 -0400 (EDT) -From: Zzzzz TTTT <zzzzz@alb-net.com> -Cc: mailman-developers@python.org -Message-ID: <Pine.GSO.4.21.0010022206280.5021-100000@alb-net.com> -Organization: "http://www.alb-net.com/" -X-Loop: ZZZZZ -MIME-Version: 1.0 -Content-Type: TEXT/PLAIN; charset=US-ASCII -Subject: [Mailman-Users] "download the full raw archive" -Sender: mailman-users-admin@python.org -Errors-To: mailman-users-admin@python.org -X-BeenThere: mailman-users@python.org -X-Mailman-Version: 2.0beta6 -Precedence: bulk -List-Help: <mailto:mailman-users-request@python.org?subject=help> -List-Post: <mailto:mailman-users@python.org> -List-Subscribe: <http://www.python.org/mailman/listinfo/mailman-users>, <mailto:mailman-users-request@python.org?subject=subscribe> -List-Id: Mailman mailing list management users <mailman-users.python.org> -List-Unsubscribe: <http://www.python.org/mailman/listinfo/mailman-users>, <mailto:mailman-users-request@python.org?subject=unsubscribe> -List-Archive: <http://www.python.org/pipermail/mailman-users/> -Date: Mon, 2 Oct 2000 22:10:10 -0400 (EDT) -X-Date-Received: Tue, 3 Oct 2000 02:11:12 -0800 -X-EdgeMail-Forward: catholic.org@catholicnet.org.uk <@@forward@@> - - -Doesn't this link run contrary to the "obscure_addresses" Option? - -Even if I have the obscure_addresses Option set to YES, the e-mail -addresses of public archives can be still harvested by various robots out -there. - -later, -Zzzzz - - ------------------------------------------------------- -Mailman-Users maillist - Mailman-Users@python.org -http://www.python.org/mailman/listinfo/mailman-users - - |
