summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/Bouncers/BouncerAPI.py64
-rw-r--r--src/mailman/app/bounces.py15
-rw-r--r--src/mailman/app/finder.py3
-rw-r--r--src/mailman/queue/bounce.py11
-rw-r--r--src/mailman/tests/test_bounces.py3
5 files changed, 24 insertions, 72 deletions
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