--- src/mailman/rules/moderation.py 2014-01-01 14:59:42 +0000
+++ src/mailman/rules/moderation.py 2014-03-12 15:42:02 +0000
@@ -87,6 +87,10 @@
assert address is not None, (
'Posting address is not registered: {0}'.format(sender))
mlist.subscribe(address, MemberRole.nonmember)
+ # If a member is found, the member-moderation rule takes precedence
+ for sender in msg.senders:
+ if mlist.members.get_member(sender) is not None:
+ return False
# Do nonmember moderation check.
for sender in msg.senders:
nonmember = mlist.nonmembers.get_member(sender)
--- /dev/null 2014-03-12 08:43:43.302994064 -0300
+++ src/mailman/rules/tests/test_moderation.py 2014-03-12 12:41:07.897168670 -0300
@@ -0,0 +1,69 @@
+# Copyright (C) 2012-2014 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman 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 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman 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
+# GNU Mailman. If not, see .
+
+"""Test the `member-moderation` and `nonmember-moderation` rules."""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'TestModeration',
+ ]
+
+
+import os
+import unittest
+
+from zope.component import getUtility
+from mailman.app.lifecycle import create_list
+from mailman.config import config
+from mailman.interfaces.member import MemberRole
+from mailman.interfaces.usermanager import IUserManager
+from mailman.rules import moderation
+from mailman.testing.helpers import (
+ specialized_message_from_string as mfs)
+from mailman.testing.layers import ConfigLayer
+
+
+
+class TestModeration(unittest.TestCase):
+ """Test the approved handler."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+
+ def test_member_and_nonmember(self):
+ anne = getUtility(IUserManager).create_address('anne@example.com')
+ bill = getUtility(IUserManager).create_address('bill@example.com')
+ self._mlist.subscribe(anne, MemberRole.member)
+ nmrule = moderation.NonmemberModeration()
+ msg = mfs("""\
+From: anne@example.com
+Sender: bill@example.com
+To: test@example.com
+Subject: A test message
+Message-ID:
+MIME-Version: 1.0
+
+A message body.
+""")
+ result = nmrule.check(self._mlist, msg, {})
+ self.assertFalse(result,
+ "The NonMemberModeration rule must not match if there are both "
+ "members and nonmembers in the senders")