summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2007-12-29 11:28:00 -0500
committerBarry Warsaw2007-12-29 11:28:00 -0500
commitbe4b3b0f7a32b586e58b3b88e7af364b3c02aba6 (patch)
tree4b898957520a66ffa568c8ecb02fcb3666c811d2
parentc70909dbe5cf6b32ddc72963fd02eda0b5bce6d2 (diff)
downloadmailman-be4b3b0f7a32b586e58b3b88e7af364b3c02aba6.tar.gz
mailman-be4b3b0f7a32b586e58b3b88e7af364b3c02aba6.tar.zst
mailman-be4b3b0f7a32b586e58b3b88e7af364b3c02aba6.zip
-rw-r--r--Mailman/Handlers/Hold.py9
-rw-r--r--Mailman/docs/hold.txt23
-rw-r--r--Mailman/docs/recipients.txt42
-rw-r--r--Mailman/rules/max_recipients.py51
4 files changed, 93 insertions, 32 deletions
diff --git a/Mailman/Handlers/Hold.py b/Mailman/Handlers/Hold.py
index 494b653da..17f49ce11 100644
--- a/Mailman/Handlers/Hold.py
+++ b/Mailman/Handlers/Hold.py
@@ -158,15 +158,6 @@ def process(mlist, msg, msgdata):
if not sender or sender[:len(listname)+6] == adminaddr:
sender = msg.get_sender(use_envelope=0)
#
- # Are there too many recipients to the message?
- if mlist.max_num_recipients > 0:
- # figure out how many recipients there are
- recips = email.utils.getaddresses(msg.get_all('to', []) +
- msg.get_all('cc', []))
- if len(recips) >= mlist.max_num_recipients:
- hold_for_approval(mlist, msg, msgdata, TooManyRecipients)
- # no return
- #
# Implicit destination? Note that message originating from the Usenet
# side of the world should never be checked for implicit destination.
if mlist.require_explicit_destination and \
diff --git a/Mailman/docs/hold.txt b/Mailman/docs/hold.txt
index 4ee5f8d67..40d3e368c 100644
--- a/Mailman/docs/hold.txt
+++ b/Mailman/docs/hold.txt
@@ -57,29 +57,6 @@ handler returns immediately.
{'approved': True}
-Maximum number of recipients
-----------------------------
-
-Mailman will hold messages that have more than a specified number of explicit
-recipients.
-
- >>> mlist.max_num_recipients = 5
- >>> msg = message_from_string("""\
- ... From: aperson@example.com
- ... To: _xtest@example.com, bperson@example.com
- ... Cc: cperson@example.com
- ... Cc: dperson@example.com (Dan Person)
- ... To: Elly Q. Person <eperson@example.com>
- ...
- ... Hey folks!
- ... """)
- >>> process(mlist, msg, {})
- Traceback (most recent call last):
- ...
- TooManyRecipients
- >>> clear()
-
-
Implicit destination
--------------------
diff --git a/Mailman/docs/recipients.txt b/Mailman/docs/recipients.txt
new file mode 100644
index 000000000..98176c8bb
--- /dev/null
+++ b/Mailman/docs/recipients.txt
@@ -0,0 +1,42 @@
+Maximum number of recipients
+============================
+
+The 'max-recipients' rule matches when there are more than the maximum allowed
+number of explicit recipients addressed by the message.
+
+ >>> from Mailman.configuration import config
+ >>> mlist = config.db.list_manager.create(u'_xtest@example.com')
+ >>> from Mailman.app.rules import find_rule
+ >>> rule = find_rule('max-recipients')
+ >>> rule.name
+ 'max-recipients'
+
+In this case, we'll create a message with 5 recipients. These include all
+addresses in the To and CC headers.
+
+ >>> msg = message_from_string(u"""\
+ ... From: aperson@example.com
+ ... To: _xtest@example.com, bperson@example.com
+ ... Cc: cperson@example.com
+ ... Cc: dperson@example.com (Dan Person)
+ ... To: Elly Q. Person <eperson@example.com>
+ ...
+ ... Hey folks!
+ ... """)
+
+For backward compatibility, the message must have fewer than the maximum
+number of explicit recipients.
+
+ >>> mlist.max_num_recipients = 5
+ >>> rule.check(mlist, msg, {})
+ True
+
+ >>> mlist.max_num_recipients = 6
+ >>> rule.check(mlist, msg, {})
+ False
+
+Zero means any number of recipients are allowed.
+
+ >>> mlist.max_num_recipients = 0
+ >>> rule.check(mlist, msg, {})
+ False
diff --git a/Mailman/rules/max_recipients.py b/Mailman/rules/max_recipients.py
new file mode 100644
index 000000000..8c2fbb370
--- /dev/null
+++ b/Mailman/rules/max_recipients.py
@@ -0,0 +1,51 @@
+# Copyright (C) 2007 by the Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
+
+"""The maximum number of recipients rule."""
+
+__all__ = ['max_recipients_rule']
+__metaclass__ = type
+
+
+from email.utils import getaddresses
+from zope.interface import implements
+
+from Mailman.i18n import _
+from Mailman.interfaces import IRule
+
+
+
+class MaximumRecipients:
+ """The maximum number of recipients rule."""
+ implements(IRule)
+
+ name = 'max-recipients'
+ description = _('Catch messages with too many explicit recipients')
+
+ def check(self, mlist, msg, msgdata):
+ """See `IRule`."""
+ # Zero means any number of recipients are allowed.
+ if mlist.max_num_recipients == 0:
+ return False
+ # Figure out how many recipients there are
+ recipients = getaddresses(msg.get_all('to', []) +
+ msg.get_all('cc', []))
+ return len(recipients) >= mlist.max_num_recipients
+
+
+
+max_recipients_rule = MaximumRecipients()