Merge branch 'alias' into 'master'
[mailman.git] / src / mailman / chains / accept.py
blob70743b38efef0bc812af7b4e9548762bc675a09b
1 # Copyright (C) 2007-2019 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)
8 # any later version.
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
13 # more details.
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 'accept' chain."""
20 import logging
22 from mailman.chains.base import TerminalChainBase
23 from mailman.config import config
24 from mailman.core.i18n import _
25 from mailman.interfaces.chain import AcceptEvent
26 from public import public
27 from zope.event import notify
30 log = logging.getLogger('mailman.vette')
31 SEMISPACE = '; '
34 @public
35 class AcceptChain(TerminalChainBase):
36 """Accept the message for posting."""
38 name = 'accept'
39 description = _('Accept a message.')
41 def _process(self, mlist, msg, msgdata):
42 """See `TerminalChainBase`."""
43 # Start by decorating the message with a header that contains a list
44 # of all the rules that matched. These metadata could be None or an
45 # empty list.
46 rule_hits = msgdata.get('rule_hits')
47 if rule_hits:
48 msg['X-Mailman-Rule-Hits'] = SEMISPACE.join(rule_hits)
49 rule_misses = msgdata.get('rule_misses')
50 if rule_misses:
51 msg['X-Mailman-Rule-Misses'] = SEMISPACE.join(rule_misses)
52 config.switchboards['pipeline'].enqueue(msg, msgdata)
53 log.info('ACCEPT: %s', msg.get('message-id', 'n/a'))
54 notify(AcceptEvent(mlist, msg, msgdata, self))