Extended test_documentation.py to be able to find doctests in subdirectories
[mailman.git] / Mailman / rules / max_recipients.py
blobdfa23f659dffcdce5ecf7685830daf4c3b9c22f5
1 # Copyright (C) 2007 by the Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
16 # USA.
18 """The maximum number of recipients rule."""
20 __all__ = ['MaximumRecipients']
21 __metaclass__ = type
24 from email.utils import getaddresses
25 from zope.interface import implements
27 from Mailman.i18n import _
28 from Mailman.interfaces import IRule
32 class MaximumRecipients:
33 """The maximum number of recipients rule."""
34 implements(IRule)
36 name = 'max-recipients'
37 description = _('Catch messages with too many explicit recipients.')
39 def check(self, mlist, msg, msgdata):
40 """See `IRule`."""
41 # Zero means any number of recipients are allowed.
42 if mlist.max_num_recipients == 0:
43 return False
44 # Figure out how many recipients there are
45 recipients = getaddresses(msg.get_all('to', []) +
46 msg.get_all('cc', []))
47 return len(recipients) >= mlist.max_num_recipients