summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/database/mailman.sql2
-rw-r--r--src/mailman/interfaces/mailinglist.py3
-rw-r--r--src/mailman/model/mailinglist.py2
-rw-r--r--src/mailman/queue/bounce.py157
-rw-r--r--src/mailman/queue/tests/test_bounce.py78
5 files changed, 85 insertions, 157 deletions
diff --git a/src/mailman/database/mailman.sql b/src/mailman/database/mailman.sql
index 103bfb8e1..7493f5d34 100644
--- a/src/mailman/database/mailman.sql
+++ b/src/mailman/database/mailman.sql
@@ -128,11 +128,11 @@ CREATE TABLE mailinglist (
autoresponse_grace_period TEXT,
-- Bounces.
forward_unrecognized_bounces_to TEXT,
+ process_bounces BOOLEAN,
bounce_info_stale_after TEXT,
bounce_matching_headers TEXT,
bounce_notify_owner_on_disable BOOLEAN,
bounce_notify_owner_on_removal BOOLEAN,
- bounce_processing BOOLEAN,
bounce_score_threshold INTEGER,
bounce_you_are_disabled_warnings INTEGER,
bounce_you_are_disabled_warnings_interval TEXT,
diff --git a/src/mailman/interfaces/mailinglist.py b/src/mailman/interfaces/mailinglist.py
index 7a25544d4..44e015435 100644
--- a/src/mailman/interfaces/mailinglist.py
+++ b/src/mailman/interfaces/mailinglist.py
@@ -505,6 +505,9 @@ class IMailingList(Interface):
forwarded to the site owner.
""")
+ process_bounces = Attribute(
+ """Whether or not the mailing list processes bounces.""")
+
class IAcceptableAlias(Interface):
diff --git a/src/mailman/model/mailinglist.py b/src/mailman/model/mailinglist.py
index e0841f6d8..2d972a24a 100644
--- a/src/mailman/model/mailinglist.py
+++ b/src/mailman/model/mailinglist.py
@@ -118,11 +118,11 @@ class MailingList(Model):
bounce_matching_headers = Unicode() # XXX
bounce_notify_owner_on_disable = Bool() # XXX
bounce_notify_owner_on_removal = Bool() # XXX
- bounce_processing = Bool() # XXX
bounce_score_threshold = Int() # XXX
bounce_you_are_disabled_warnings = Int() # XXX
bounce_you_are_disabled_warnings_interval = TimeDelta() # XXX
forward_unrecognized_bounces_to = Enum()
+ process_bounces = Bool()
# Miscellaneous
default_member_action = Enum()
default_nonmember_action = Enum()
diff --git a/src/mailman/queue/bounce.py b/src/mailman/queue/bounce.py
index 8787332e7..819f0e368 100644
--- a/src/mailman/queue/bounce.py
+++ b/src/mailman/queue/bounce.py
@@ -17,16 +17,10 @@
"""Bounce queue runner."""
-import os
-import cPickle
import logging
-import datetime
-
-from lazr.config import as_timedelta
from mailman.app.bounces import StandardVERP
from mailman.config import config
-from mailman.core.i18n import _
from mailman.interfaces.bounce import Stop
from mailman.queue import Runner
@@ -37,155 +31,14 @@ log = logging.getLogger('mailman.bounce')
elog = logging.getLogger('mailman.error')
-
-class BounceMixin:
- def __init__(self):
- # Registering a bounce means acquiring the list lock, and it would be
- # too expensive to do this for each message. Instead, each bounce
- # runner maintains an event log which is essentially a file with
- # multiple pickles. Each bounce we receive gets appended to this file
- # as a 4-tuple record: (listname, addr, today, msg)
- #
- # today is itself a 3-tuple of (year, month, day)
- #
- # Every once in a while (see _do_periodic()), the bounce runner cracks
- # open the file, reads all the records and registers all the bounces.
- # Then it truncates the file and continues on. We don't need to lock
- # the bounce event file because bounce qrunners are single threaded
- # and each creates a uniquely named file to contain the events.
- #
- # XXX When Python 2.3 is minimal require, we can use the new
- # tempfile.TemporaryFile() function.
- #
- # XXX We used to classify bounces to the site list as bounce events
- # for every list, but this caused severe problems. Here's the
- # scenario: aperson@example.com is a member of 4 lists, and a list
- # owner of the foo list. example.com has an aggressive spam filter
- # which rejects any message that is spam or contains spam as an
- # attachment. Now, a spambot sends a piece of spam to the foo list,
- # but since that spambot is not a member, the list holds the message
- # for approval, and sends a notification to aperson@example.com as
- # list owner. That notification contains a copy of the spam. Now
- # example.com rejects the message, causing a bounce to be sent to the
- # site list's bounce address. The bounce runner would then dutifully
- # register a bounce for all 4 lists that aperson@example.com was a
- # member of, and eventually that person would get disabled on all
- # their lists. So now we ignore site list bounces. Ce La Vie for
- # password reminder bounces.
- self._bounce_events_file = os.path.join(
- config.DATA_DIR, 'bounce-events-%05d.pck' % os.getpid())
- self._bounce_events_fp = None
- self._bouncecnt = 0
- self._nextaction = (
- datetime.datetime.now() +
- as_timedelta(config.bounces.register_bounces_every))
-
- def _queue_bounces(self, listname, addrs, msg):
- today = datetime.date.today()
- if self._bounce_events_fp is None:
- self._bounce_events_fp = open(self._bounce_events_file, 'a+b')
- for addr in addrs:
- cPickle.dump((listname, addr, today, msg),
- self._bounce_events_fp, 1)
- self._bounce_events_fp.flush()
- os.fsync(self._bounce_events_fp.fileno())
- self._bouncecnt += len(addrs)
-
- def _register_bounces(self):
- log.info('%s processing %s queued bounces', self, self._bouncecnt)
- # Read all the records from the bounce file, then unlink it. Sort the
- # records by listname for more efficient processing.
- events = {}
- self._bounce_events_fp.seek(0)
- while True:
- try:
- listname, addr, day, msg = cPickle.load(self._bounce_events_fp)
- except ValueError, e:
- log.error('Error reading bounce events: %s', e)
- except EOFError:
- break
- events.setdefault(listname, []).append((addr, day, msg))
- # Now register all events sorted by list
- for listname in events.keys():
- mlist = self._open_list(listname)
- mlist.Lock()
- try:
- for addr, day, msg in events[listname]:
- mlist.registerBounce(addr, msg, day=day)
- mlist.Save()
- finally:
- mlist.Unlock()
- # Reset and free all the cached memory
- self._bounce_events_fp.close()
- self._bounce_events_fp = None
- os.unlink(self._bounce_events_file)
- self._bouncecnt = 0
-
- def _clean_up(self):
- if self._bouncecnt > 0:
- self._register_bounces()
-
- def _do_periodic(self):
- now = datetime.datetime.now()
- if self._nextaction > now or self._bouncecnt == 0:
- return
- # Let's go ahead and register the bounces we've got stored up
- self._nextaction = now + as_timedelta(
- config.bounces.register_bounces_every)
- self._register_bounces()
-
- def _probe_bounce(self, mlist, token):
- locked = mlist.Locked()
- if not locked:
- mlist.Lock()
- try:
- op, addr, bmsg = mlist.pend_confirm(token)
- info = mlist.getBounceInfo(addr)
- mlist.disableBouncingMember(addr, info, bmsg)
- # Only save the list if we're unlocking it
- if not locked:
- mlist.Save()
- finally:
- if not locked:
- mlist.Unlock()
-
-
-class BounceRunner(Runner, BounceMixin):
+class BounceRunner(Runner):
"""The bounce runner."""
- def __init__(self, slice=None, numslices=1):
- Runner.__init__(self, slice, numslices)
- BounceMixin.__init__(self)
-
def _dispose(self, mlist, msg, msgdata):
- # Make sure we have the most up-to-date state
- mlist.Load()
- # There are a few possibilities here:
- #
- # - the message could have been VERP'd in which case, we know exactly
- # who the message was destined for. That make our job easy.
- # - the message could have been originally destined for a list owner,
- # but a list owner address itself bounced. That's bad, and for now
- # we'll simply log the problem and attempt to deliver the message to
- # the site owner.
- #
- # All messages sent to list owners have their sender set to the site
- # owner address. That way, if a list owner address bounces, at least
- # some human has a chance to deal with it. Is this a bounce for a
- # message to a list owner, coming to the site owner?
- if msg.get('to', '') == config.mailman.site_owner:
- # Send it on to the site owners, but craft the envelope sender to
- # be the noreply address, so if the site owner bounce, we won't
- # get stuck in a bounce loop.
- config.switchboards['out'].enqueue(
- msg, msgdata,
- recipients=[config.mailman.site_owner],
- envsender=config.mailman.noreply_address,
- )
# List isn't doing bounce processing?
if not mlist.bounce_processing:
- return
+ return False
# Try VERP detection first, since it's quick and easy
addrs = StandardVERP().get_verp(mlist, msg)
if addrs:
@@ -216,9 +69,3 @@ class BounceRunner(Runner, BounceMixin):
# 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)
-
- _do_periodic = BounceMixin._do_periodic
-
- def _clean_up(self):
- BounceMixin._clean_up(self)
- Runner._clean_up(self)
diff --git a/src/mailman/queue/tests/test_bounce.py b/src/mailman/queue/tests/test_bounce.py
new file mode 100644
index 000000000..ba2476e79
--- /dev/null
+++ b/src/mailman/queue/tests/test_bounce.py
@@ -0,0 +1,78 @@
+# Copyright (C) 2011 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/>.
+
+"""Test the bounce queue runner."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'test_suite',
+ ]
+
+
+import unittest
+
+from zope.component import getUtility
+
+from mailman.app.lifecycle import create_list
+from mailman.config import config
+from mailman.interfaces.member import MemberRole
+from mailman.interfaces.usermanager import IUserManager
+from mailman.queue.bounce import BounceRunner
+from mailman.testing.helpers import (
+ get_queue_messages,
+ make_testable_runner,
+ specialized_message_from_string as message_from_string)
+from mailman.testing.layers import ConfigLayer
+
+
+
+class TestBounceQueue(unittest.TestCase):
+ """Test the bounce queue runner."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+ self._bounceq = config.switchboards['bounces']
+ self._runner = make_testable_runner(BounceRunner, 'bounces')
+ self._anne = getUtility(IUserManager).create_address(
+ 'anne@example.com')
+ self._member = self._mlist.subscribe(self._anne, MemberRole.member)
+ self._msg = message_from_string("""\
+From: mail-daemon@example.com
+To: test-bounce+anne=example.com@example.com
+Message-Id: <first>
+
+""")
+ self._msgdata = dict(listname='test@example.com')
+
+ def test_does_no_processing(self):
+ # If the mailing list does no bounce processing, the messages are
+ # simply discarded.
+ self._mlist.bounce_processing = False
+ self._bounceq.enqueue(self._msg, self._msgdata)
+ self._runner.run()
+ self.assertEqual(len(get_queue_messages('bounces')), 0)
+
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestBounceQueue))
+ return suite