Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core


Commits:
507b8b6d by Mark Sapiro at 2022-03-11T09:56:55-08:00
Don't return before sender's loop is completed.

- - - - -
4dfadcb5 by Mark Sapiro at 2022-03-11T18:27:24+00:00
Merge branch 'nonmember' into 'master'

Don't return before sender's loop is completed.

See merge request mailman/mailman!983
- - - - -


3 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/rules/moderation.py
- src/mailman/rules/tests/test_moderation.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -43,6 +43,8 @@ Bugs fixed
   set via REST.  (Closes #974)
 * Override the as_bytes() method in the mailman.email.message.Message class to
   workaround https://bugs.python.org/issue41307.  (Closes #979 and #980)
+* The nonmember moderation rule now checks all senders, not just the first.
+  (Closes #986)
 
 REST
 ====


=====================================
src/mailman/rules/moderation.py
=====================================
@@ -206,8 +206,7 @@ class NonmemberModeration:
                                   .format(addr, action_name, mlist.list_id,
                                           error.msg))
                         continue
-            # No nonmember.moderation.action and no legacy hits.
-            action = mlist.default_nonmember_action
-            return _do_action(msgdata, action, sender)
-        # The sender must be a member, so this rule does not match.
-        return False
+            # No nonmember.moderation.action and no legacy hits for this
+            # sender - continue
+        action = mlist.default_nonmember_action
+        return _do_action(msgdata, action, sender)


=====================================
src/mailman/rules/tests/test_moderation.py
=====================================
@@ -231,6 +231,84 @@ A message body.
             msgdata['member_moderation_action'], 'hold',
             'Wrong action for {}: {}'.format(address, 'hold'))
 
+    def test_subsequent_nonmember_in_accept_these_may_post(self):
+        # A nonmember sender not first in the senders list and in
+        # accept_these_nonmembers may post.
+        # https://gitlab.com/mailman/mailman/-/issues/986
+        self._mlist.default_nonmember_action = Action.hold
+        setattr(self._mlist, 'accept_these_nonmembers', ['b...@example.com'])
+        user_manager = getUtility(IUserManager)
+        user_manager.create_address('a...@example.com')
+        user_manager.create_address('b...@example.com')
+        rule = moderation.NonmemberModeration()
+        msg = mfs("""\
+From: a...@example.com
+Sender: b...@example.com
+To: t...@example.com
+Subject: A test message
+Message-ID: <ant>
+MIME-Version: 1.0
+
+A message body.
+""")
+        msgdata = {}
+        result = rule.check(self._mlist, msg, msgdata)
+        self.assertFalse(result, 'NonmemberModeration rule should not hit')
+
+    def test_subsequent_nonmember_with_accept_action_may_post(self):
+        # A nonmember sender not first in the senders list and with explicit
+        # moderation_action accept may post.
+        # https://gitlab.com/mailman/mailman/-/issues/986
+        self._mlist.default_nonmember_action = Action.hold
+        user_manager = getUtility(IUserManager)
+        user_manager.create_address('a...@example.com')
+        bart = user_manager.create_address('b...@example.com')
+        nonmember = self._mlist.subscribe(bart, MemberRole.nonmember)
+        nonmember.moderation_action = Action.accept
+        rule = moderation.NonmemberModeration()
+        msg = mfs("""\
+From: a...@example.com
+Sender: b...@example.com
+To: t...@example.com
+Subject: A test message
+Message-ID: <ant>
+MIME-Version: 1.0
+
+A message body.
+""")
+        msgdata = {}
+        result = rule.check(self._mlist, msg, msgdata)
+        self.assertEqual(msgdata['member_moderation_action'], 'accept')
+        self.assertEqual(msgdata['moderation_sender'], 'b...@example.com')
+        self.assertEqual(msgdata['moderation_reasons'][0],
+                         'The message is not from a list member')
+        self.assertTrue(result, 'NonmemberModeration should hit')
+
+    def test_subsequent_nonmember_with_defer_action_may_post(self):
+        # A nonmember sender not first in the senders list and with explicit
+        # moderation_action defer may post.
+        # https://gitlab.com/mailman/mailman/-/issues/986
+        self._mlist.default_nonmember_action = Action.hold
+        user_manager = getUtility(IUserManager)
+        user_manager.create_address('a...@example.com')
+        bart = user_manager.create_address('b...@example.com')
+        nonmember = self._mlist.subscribe(bart, MemberRole.nonmember)
+        nonmember.moderation_action = Action.defer
+        rule = moderation.NonmemberModeration()
+        msg = mfs("""\
+From: a...@example.com
+Sender: b...@example.com
+To: t...@example.com
+Subject: A test message
+Message-ID: <ant>
+MIME-Version: 1.0
+
+A message body.
+""")
+        msgdata = {}
+        result = rule.check(self._mlist, msg, msgdata)
+        self.assertFalse(result, 'NonmemberModeration should not hit')
+
     def test_nonmember_fallback_to_list_defaults(self):
         # https://gitlab.com/mailman/mailman/issues/189
         self._mlist.default_nonmember_action = Action.hold



View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/5674e84eb58ba23200d41ccc45b0d09c3e8374f2...4dfadcb5b92d45114621ef5dd1f55e5d5fd28cd4

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/5674e84eb58ba23200d41ccc45b0d09c3e8374f2...4dfadcb5b92d45114621ef5dd1f55e5d5fd28cd4
You're receiving this email because of your account on gitlab.com.


_______________________________________________
Mailman-checkins mailing list -- mailman-checkins@python.org
To unsubscribe send an email to mailman-checkins-le...@python.org
https://mail.python.org/mailman3/lists/mailman-checkins.python.org/
Member address: arch...@jab.org

Reply via email to