1
# Copyright (C) 2001-2012 by the Free Software Foundation, Inc.
3
# This file is part of GNU Mailman.
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free
7
# Software Foundation, either version 3 of the License, or (at your option)
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
# You should have received a copy of the GNU General Public License along with
16
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
22
from flufl.bounce import all_failures, scan_message
23
from zope.component import getUtility
25
from mailman.app.bounces import ProbeVERP, StandardVERP, maybe_forward
26
from mailman.core.runner import Runner
27
from mailman.interfaces.bounce import BounceContext, IBounceProcessor
32
log = logging.getLogger('mailman.bounce')
33
elog = logging.getLogger('mailman.error')
37
class BounceRunner(Runner):
38
"""The bounce runner."""
40
def __init__(self, name, slice=None):
41
super(BounceRunner, self).__init__(name, slice)
42
self._processor = getUtility(IBounceProcessor)
44
def _dispose(self, mlist, msg, msgdata):
45
# List isn't doing bounce processing?
46
if not mlist.process_bounces:
48
# Try VERP detection first, since it's quick and easy
49
context = BounceContext.normal
50
addresses = StandardVERP().get_verp(mlist, msg)
51
if len(addresses) > 0:
52
# Scan the message to see if it contained permanent or temporary
53
# failures. We'll ignore temporary failures, but even if there
54
# are no permanent failures, we'll assume VERP bounces are
56
temporary, permanent = all_failures(msg)
57
if len(temporary) > 0:
58
# This was a temporary failure, so just ignore it.
61
# See if this was a probe message.
62
addresses = ProbeVERP().get_verp(mlist, msg)
63
if len(addresses) > 0:
64
context = BounceContext.probe
66
# That didn't give us anything useful, so try the old fashion
67
# bounce matching modules. This returns only the permanently
68
# failing addresses. Since Mailman currently doesn't score
69
# temporary failures, if we get no permanent failures, we're
71
addresses = scan_message(msg)
72
# If that still didn't return us any useful addresses, then send it on
73
# or discard it. The addresses will come back from flufl.bounce as
74
# bytes/8-bit strings, but we must store them as unicodes in the
75
# database. Assume utf-8 encoding, but be cautious.
76
if len(addresses) > 0:
77
for address in addresses:
78
if isinstance(address, bytes):
80
address = address.decode('utf-8')
82
log.exception('Ignoring non-UTF-8 encoded '
83
'address: {0}'.format(address))
85
self._processor.register(mlist, address, msg, context)
87
log.info('Bounce message w/no discernable addresses: %s',
88
msg.get('message-id', 'n/a'))
89
maybe_forward(mlist, msg)
90
# Dequeue this message.