1 # Copyright (C) 2007-2016 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/>.
18 """The terminal 'reject' chain."""
22 from mailman
import public
23 from mailman
.app
.bounces
import bounce_message
24 from mailman
.chains
.base
import TerminalChainBase
25 from mailman
.core
.i18n
import _
26 from mailman
.interfaces
.chain
import RejectEvent
27 from mailman
.interfaces
.pipeline
import RejectMessage
28 from zope
.event
import notify
31 log
= logging
.getLogger('mailman.vette')
38 class RejectChain(TerminalChainBase
):
39 """Reject/bounce a message."""
42 description
= _('Reject/bounce a message and stop processing.')
44 def _process(self
, mlist
, msg
, msgdata
):
45 """See `TerminalChainBase`."""
46 # Start by decorating the message with a header that contains a list
47 # of all the rules that matched. These metadata could be None or an
49 rule_hits
= msgdata
.get('rule_hits')
51 msg
['X-Mailman-Rule-Hits'] = SEMISPACE
.join(rule_hits
)
52 rule_misses
= msgdata
.get('rule_misses')
54 msg
['X-Mailman-Rule-Misses'] = SEMISPACE
.join(rule_misses
)
55 reasons
= msgdata
.get('moderation_reasons')
59 error
= RejectMessage(_("""
60 Your message to the {list_name} mailing-list was rejected for the following
65 The original message as received by Mailman is attached.
67 list_name
=mlist
.display_name
, # noqa
68 reasons
=NEWLINE
.join(reasons
) # noqa
70 bounce_message(mlist
, msg
, error
)
71 log
.info('REJECT: %s', msg
.get('message-id', 'n/a'))
72 notify(RejectEvent(mlist
, msg
, msgdata
, self
))