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


Commits:
c12e8d49 by Mark Sapiro at 2021-11-06T13:10:18-07:00
Don't remove held message from store if there are other requests for it.

- - - - -
84040cab by Mark Sapiro at 2021-11-06T20:37:34+00:00
Merge branch 'held' into 'master'

Don't remove held message from store if there are other requests for it.

See merge request mailman/mailman!932
- - - - -


3 changed files:

- src/mailman/app/moderator.py
- src/mailman/app/tests/test_moderation.py
- src/mailman/docs/NEWS.rst


Changes:

=====================================
src/mailman/app/moderator.py
=====================================
@@ -189,7 +189,7 @@ def handle_message(mlist, id, action, comment=None, 
forward=None):
     # Delete the request and message if it's not being kept.
     if not keep:
         # There are two pended tokens.  The request id has the moderator
-        # token, but wee need to delete the user token too.
+        # token, but we need to delete the user token too.
         user_token = None
         pendings = getUtility(IPendings)
         for token, data in pendings.find(pend_type='held message'):
@@ -200,7 +200,14 @@ def handle_message(mlist, id, action, comment=None, 
forward=None):
         if user_token is not None:
             pendings.confirm(user_token, expunge=True)
         requestdb.delete_request(id)
-        message_store.delete_message(message_id)
+        # Only delete the message from the message store if there's no other
+        # request for it.
+        delete = True
+        for token, data in pendings.find(pend_type='data'):
+            if data['_mod_message_id'] == message_id:
+                delete = False
+        if delete:
+            message_store.delete_message(message_id)
     # Log the rejection
     if rejection:
         note = """%s: %s posting:


=====================================
src/mailman/app/tests/test_moderation.py
=====================================
@@ -206,9 +206,36 @@ Message-ID: <alpha>
         self.assertIsNone(message)
         self.assertIsNone(getUtility(IPendings).confirm(hash))
 
+    def test_handled_cross_posted_message_not_removed(self):
+        # A cross posted message is not removed when handled on the first list.
+        mlist2 = create_list('te...@example.com')
+        request_db2 = IListRequests(mlist2)
+        request_id = hold_message(self._mlist, self._msg)
+        request_id2 = hold_message(mlist2, self._msg)
+        # Get the hashes for these pending requests.
+        hash0 = list(self._request_db.held_requests)[0].data_hash
+        hash1 = list(request_db2.held_requests)[0].data_hash
+        # Handle the first list's message.
+        handle_message(self._mlist, request_id, Action.discard)
+        # There's now only the request for list2.
+        self.assertEqual(self._request_db.count, 0)
+        self.assertEqual(request_db2.count, 1)
+        message = getUtility(IMessageStore).get_message_by_id('<alpha>')
+        self.assertIsNotNone(message)
+        self.assertIsNone(getUtility(IPendings).confirm(hash0))
+        self.assertIsNotNone(getUtility(IPendings).confirm(hash1,
+                                                           expunge=False))
+        # Handle the second list's message.
+        handle_message(mlist2, request_id2, Action.discard)
+        # Now the request and message are gone.
+        self.assertEqual(request_db2.count, 0)
+        message = getUtility(IMessageStore).get_message_by_id('<alpha>')
+        self.assertIsNone(message)
+        self.assertIsNone(getUtility(IPendings).confirm(hash1))
+
     def test_all_pendings_removed(self):
         # A held message pends two tokens, One for the moderator and one for
-        # the user.  Ensure both are removed when meddage is handled.
+        # the user.  Ensure both are removed when message is handled.
         request_id = hold_message(self._mlist, self._msg)
         # The hold chain does more.
         pendings = getUtility(IPendings)


=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -20,6 +20,8 @@ Bugs fixed
 * The ``mailman members`` command reports incompatible options that would
   otherwise throw exceptions.
 * Require authheaders >=0.14.0 and adjust tests accordingly.  (Closes #954)
+* Handling a held message will not remove it from the message store if there
+  are other requests for it.  (Closes #955)
 
 .. _news-3.3.5:
 



View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/df4eb855e2bebc096ad235fc4ed3b2035878474d...84040cabdc69e8362da402f86b174ec4a82d9014

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/df4eb855e2bebc096ad235fc4ed3b2035878474d...84040cabdc69e8362da402f86b174ec4a82d9014
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