1# Copyright (C) 2007-2020 by the Free Software Foundation, Inc.
2#
3# This file is part of GNU Mailman.
4#
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.
9#
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.
14#
15# You should have received a copy of the GNU General Public License along with
16# GNU Mailman.  If not, see <https://www.gnu.org/licenses/>.
17
18"""The news moderation rule."""
19
20from mailman.core.i18n import _
21from mailman.interfaces.nntp import NewsgroupModeration
22from mailman.interfaces.rules import IRule
23from public import public
24from zope.interface import implementer
25
26
27@public
28@implementer(IRule)
29class ModeratedNewsgroup:
30    """The news moderation rule."""
31
32    name = 'news-moderation'
33    description = _(
34        """Match all messages posted to a mailing list that gateways to a
35        moderated newsgroup.
36        """)
37    record = True
38
39    def check(self, mlist, msg, msgdata):
40        """See `IRule`."""
41        if mlist.newsgroup_moderation is NewsgroupModeration.moderated:
42            msgdata['moderation_sender'] = msg.sender
43            with _.defer_translation():
44                # This will be translated at the point of use.
45                msgdata.setdefault('moderation_reasons', []).append(
46                    _('Post to a moderated newsgroup gateway'))
47            return True
48        return False
49