~barry/mailman/events-and-web

« back to all changes in this revision

Viewing changes to src/mailman/rules/max_recipients.py

  • Committer: klm
  • Date: 1998-01-07 21:21:35 UTC
  • Revision ID: vcs-imports@canonical.com-19980107212135-sv0y521ps0xye37r
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2012 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 <http://www.gnu.org/licenses/>.
17
 
 
18
 
"""The maximum number of recipients rule."""
19
 
 
20
 
from __future__ import absolute_import, print_function, unicode_literals
21
 
 
22
 
__metaclass__ = type
23
 
__all__ = [
24
 
    'MaximumRecipients',
25
 
    ]
26
 
 
27
 
 
28
 
from email.utils import getaddresses
29
 
from zope.interface import implementer
30
 
 
31
 
from mailman.core.i18n import _
32
 
from mailman.interfaces.rules import IRule
33
 
 
34
 
 
35
 
 
36
 
@implementer(IRule)
37
 
class MaximumRecipients:
38
 
    """The maximum number of recipients rule."""
39
 
 
40
 
    name = 'max-recipients'
41
 
    description = _('Catch messages with too many explicit recipients.')
42
 
    record = True
43
 
 
44
 
    def check(self, mlist, msg, msgdata):
45
 
        """See `IRule`."""
46
 
        # Zero means any number of recipients are allowed.
47
 
        if mlist.max_num_recipients == 0:
48
 
            return False
49
 
        # Figure out how many recipients there are
50
 
        recipients = getaddresses(msg.get_all('to', []) +
51
 
                                  msg.get_all('cc', []))
52
 
        return len(recipients) >= mlist.max_num_recipients