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


Commits:
5a25970f by Mark Sapiro at 2021-01-20T15:48:49-08:00
Added reasons to vette log discard message.

- - - - -
836a9b93 by Mark Sapiro at 2021-01-21T00:46:48+00:00
Merge branch 'discard' into 'master'

Added reasons to vette log discard message.

Closes #816

See merge request mailman/mailman!766
- - - - -


3 changed files:

- src/mailman/chains/discard.py
- + src/mailman/chains/tests/test_discard.py
- src/mailman/docs/NEWS.rst


Changes:

=====================================
src/mailman/chains/discard.py
=====================================
@@ -42,6 +42,7 @@ class DiscardChain(TerminalChainBase):
         This writes a log message, fires a Zope event and then throws the
         message away.
         """
-        log.info('DISCARD: %s', msg.get('message-id', 'n/a'))
+        log.info('DISCARD: %s; %s', msg.get('message-id', 'n/a'),
+                 msgdata.get('moderation_reasons', '[n/a]'))
         notify(DiscardEvent(mlist, msg, msgdata, self))
         # Nothing more needs to happen.


=====================================
src/mailman/chains/tests/test_discard.py
=====================================
@@ -0,0 +1,61 @@
+# Copyright (C) 2015-2021 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 <https://www.gnu.org/licenses/>.
+
+"""Test the discard chain."""
+
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.core.chains import process as process_chain
+from mailman.testing.helpers import (
+    LogFileMark, specialized_message_from_string as mfs)
+from mailman.testing.layers import ConfigLayer
+
+
+class TestDiscard(unittest.TestCase):
+    """Test the discard chain."""
+
+    layer = ConfigLayer
+
+    def setUp(self):
+        self._mlist = create_list('t...@example.com')
+        self._msg = mfs("""\
+From: a...@example.com
+To: t...@example.com
+Subject: Ignore
+Message-Id: <m...@example.com>
+
+""")
+
+    def test_discard_reasons(self):
+        # The log message must contain the moderation reasons.
+        msgdata = dict(moderation_reasons=['TEST-REASON-1', 'TEST-REASON-2'])
+        log_file = LogFileMark('mailman.vette')
+        process_chain(self._mlist, self._msg, msgdata, start_chain='discard')
+        log_entry = log_file.read()
+        self.assertIn('DISCARD: <m...@example.com>', log_entry)
+        self.assertIn('TEST-REASON-1', log_entry)
+        self.assertIn('TEST-REASON-2', log_entry)
+
+    def test_discard_no_reasons(self):
+        # The log message contains n/a if no moderation reasons.
+        msgdata = {}
+        log_file = LogFileMark('mailman.vette')
+        process_chain(self._mlist, self._msg, msgdata, start_chain='discard')
+        log_entry = log_file.read()
+        self.assertIn('DISCARD: <m...@example.com>', log_entry)
+        self.assertIn('[n/a]', log_entry)


=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -36,6 +36,8 @@ Bugs
   (Closes #809)
 * Header filters will now properly match RFC 2047 encoded headers.
   (Closes #815)
+* Mailman's ``vette`` log discard messages now include the reasons.
+  (Closes #816)
 
 Command line
 ------------



View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/20adbc6b5f4f812f0e87086fb67f3066bc279935...836a9b93f71e9d25449f66ae5b57406d1f3252f6

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/20adbc6b5f4f812f0e87086fb67f3066bc279935...836a9b93f71e9d25449f66ae5b57406d1f3252f6
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