summaryrefslogtreecommitdiff
path: root/src/mailman/rules
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/rules')
-rw-r--r--src/mailman/rules/administrivia.py2
-rw-r--r--src/mailman/rules/any.py2
-rw-r--r--src/mailman/rules/approved.py2
-rw-r--r--src/mailman/rules/emergency.py2
-rw-r--r--src/mailman/rules/implicit_dest.py2
-rw-r--r--src/mailman/rules/loop.py2
-rw-r--r--src/mailman/rules/max_recipients.py2
-rw-r--r--src/mailman/rules/max_size.py2
-rw-r--r--src/mailman/rules/moderation.py6
-rw-r--r--src/mailman/rules/news_moderation.py2
-rw-r--r--src/mailman/rules/no_subject.py2
-rw-r--r--src/mailman/rules/suspicious.py2
-rw-r--r--src/mailman/rules/tests/test_approved.py2
-rw-r--r--src/mailman/rules/tests/test_moderation.py78
-rw-r--r--src/mailman/rules/truth.py2
15 files changed, 96 insertions, 14 deletions
diff --git a/src/mailman/rules/administrivia.py b/src/mailman/rules/administrivia.py
index b09c240e4..9d30d8cf0 100644
--- a/src/mailman/rules/administrivia.py
+++ b/src/mailman/rules/administrivia.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2007-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/rules/any.py b/src/mailman/rules/any.py
index 804aa8fa9..e5f80fbc4 100644
--- a/src/mailman/rules/any.py
+++ b/src/mailman/rules/any.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2007-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/rules/approved.py b/src/mailman/rules/approved.py
index f6dc82dd5..2839ffef4 100644
--- a/src/mailman/rules/approved.py
+++ b/src/mailman/rules/approved.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2007-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/rules/emergency.py b/src/mailman/rules/emergency.py
index a79b8ebe7..ba7abe562 100644
--- a/src/mailman/rules/emergency.py
+++ b/src/mailman/rules/emergency.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2007-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/rules/implicit_dest.py b/src/mailman/rules/implicit_dest.py
index 339485089..8bfb0d2e0 100644
--- a/src/mailman/rules/implicit_dest.py
+++ b/src/mailman/rules/implicit_dest.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2007-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/rules/loop.py b/src/mailman/rules/loop.py
index 0bb8e0c74..145af8b34 100644
--- a/src/mailman/rules/loop.py
+++ b/src/mailman/rules/loop.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2007-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/rules/max_recipients.py b/src/mailman/rules/max_recipients.py
index c24a19d1d..3b1d4f0c5 100644
--- a/src/mailman/rules/max_recipients.py
+++ b/src/mailman/rules/max_recipients.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2007-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/rules/max_size.py b/src/mailman/rules/max_size.py
index 18ace1b1c..1e2b46184 100644
--- a/src/mailman/rules/max_size.py
+++ b/src/mailman/rules/max_size.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2007-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/rules/moderation.py b/src/mailman/rules/moderation.py
index 0485f3018..46ed242fa 100644
--- a/src/mailman/rules/moderation.py
+++ b/src/mailman/rules/moderation.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2007-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
@@ -87,6 +87,10 @@ class NonmemberModeration:
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)
diff --git a/src/mailman/rules/news_moderation.py b/src/mailman/rules/news_moderation.py
index 32b616bf7..c4372eb80 100644
--- a/src/mailman/rules/news_moderation.py
+++ b/src/mailman/rules/news_moderation.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2007-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/rules/no_subject.py b/src/mailman/rules/no_subject.py
index 3a387d954..8f01f0c15 100644
--- a/src/mailman/rules/no_subject.py
+++ b/src/mailman/rules/no_subject.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2007-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/rules/suspicious.py b/src/mailman/rules/suspicious.py
index 55a9028c8..1841ed69e 100644
--- a/src/mailman/rules/suspicious.py
+++ b/src/mailman/rules/suspicious.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2007-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/rules/tests/test_approved.py b/src/mailman/rules/tests/test_approved.py
index 27b4a106f..e7f122410 100644
--- a/src/mailman/rules/tests/test_approved.py
+++ b/src/mailman/rules/tests/test_approved.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2012-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/rules/tests/test_moderation.py b/src/mailman/rules/tests/test_moderation.py
new file mode 100644
index 000000000..c0c3cf417
--- /dev/null
+++ b/src/mailman/rules/tests/test_moderation.py
@@ -0,0 +1,78 @@
+# Copyright (C) 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 <http://www.gnu.org/licenses/>.
+
+"""Test the `member-moderation` and `nonmember-moderation` rules."""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'TestModeration',
+ ]
+
+
+import unittest
+
+from mailman.app.lifecycle import create_list
+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
+from zope.component import getUtility
+
+
+
+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):
+ user_manager = getUtility(IUserManager)
+ anne = user_manager.create_address('anne@example.com')
+ user_manager.create_address('bill@example.com')
+ self._mlist.subscribe(anne, MemberRole.member)
+ rule = moderation.NonmemberModeration()
+ msg = mfs("""\
+From: anne@example.com
+Sender: bill@example.com
+To: test@example.com
+Subject: A test message
+Message-ID: <ant>
+MIME-Version: 1.0
+
+A message body.
+""")
+ # Both Anne and Bill are in the message's senders list.
+ self.assertIn('anne@example.com', msg.senders)
+ self.assertIn('bill@example.com', msg.senders)
+ # The NonmemberModeration rule should *not* hit, because even though
+ # Bill is in the list of senders he is not a member of the mailing
+ # list. Anne is also in the list of senders and she *is* a member, so
+ # she takes precedence.
+ result = rule.check(self._mlist, msg, {})
+ self.assertFalse(result, 'NonmemberModeration rule should not hit')
+ # After the rule runs, Bill becomes a non-member.
+ bill_member = self._mlist.nonmembers.get_member('bill@example.com')
+ self.assertIsNotNone(bill_member)
+ # Bill is not a member.
+ bill_member = self._mlist.members.get_member('bill@example.com')
+ self.assertIsNone(bill_member)
diff --git a/src/mailman/rules/truth.py b/src/mailman/rules/truth.py
index f94f9a09e..d50b5eae4 100644
--- a/src/mailman/rules/truth.py
+++ b/src/mailman/rules/truth.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2008-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2008-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#