summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/archiving/mhonarc.py7
-rw-r--r--src/mailman/archiving/tests/fake_mhonarc.py35
-rw-r--r--src/mailman/archiving/tests/test_mhonarc.py89
-rw-r--r--src/mailman/archiving/tests/test_prototype.py2
-rw-r--r--src/mailman/docs/NEWS.rst2
5 files changed, 131 insertions, 4 deletions
diff --git a/src/mailman/archiving/mhonarc.py b/src/mailman/archiving/mhonarc.py
index 1c351748e..3d414c8da 100644
--- a/src/mailman/archiving/mhonarc.py
+++ b/src/mailman/archiving/mhonarc.py
@@ -23,12 +23,12 @@ __all__ = [
import logging
-import subprocess
from mailman.config import config
from mailman.config.config import external_configuration
from mailman.interfaces.archiver import IArchiver
from mailman.utilities.string import expand
+from subprocess import PIPE, Popen
from urllib.parse import urljoin
from zope.interface import implementer
@@ -82,8 +82,9 @@ class MHonArc:
substitutions = config.__dict__.copy()
substitutions['listname'] = mlist.fqdn_listname
command = expand(self.command, substitutions)
- proc = subprocess.Popen(
- command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ proc = Popen(
+ command,
+ stdin=PIPE, stdout=PIPE, stderr=PIPE,
universal_newlines=True, shell=True)
stdout, stderr = proc.communicate(msg.as_string())
if proc.returncode != 0:
diff --git a/src/mailman/archiving/tests/fake_mhonarc.py b/src/mailman/archiving/tests/fake_mhonarc.py
new file mode 100644
index 000000000..12e60337f
--- /dev/null
+++ b/src/mailman/archiving/tests/fake_mhonarc.py
@@ -0,0 +1,35 @@
+# Copyright (C) 2015 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/>.
+
+"""A fake MHonArc process that reads stdin and writes stdout."""
+
+import sys
+
+from email import message_from_string
+
+
+def main():
+ text = sys.stdin.read()
+ msg = message_from_string(text)
+ output_file = sys.argv[1]
+ with open(output_file, 'w', encoding='utf-8') as fp:
+ print(msg['message-id'], file=fp)
+ print(msg['message-id-hash'], file=fp)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/src/mailman/archiving/tests/test_mhonarc.py b/src/mailman/archiving/tests/test_mhonarc.py
new file mode 100644
index 000000000..515d3ca49
--- /dev/null
+++ b/src/mailman/archiving/tests/test_mhonarc.py
@@ -0,0 +1,89 @@
+# Copyright (C) 2015 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 MHonArc archiver."""
+
+__all__ = [
+ 'TestMhonarc',
+ ]
+
+
+import os
+import sys
+import shutil
+import tempfile
+import unittest
+
+from mailman.archiving.mhonarc import MHonArc
+from mailman.app.lifecycle import create_list
+from mailman.database.transaction import transaction
+from mailman.testing.helpers import (
+ configuration, specialized_message_from_string as mfs)
+from mailman.testing.layers import ConfigLayer
+from pkg_resources import resource_filename
+
+
+class TestMhonarc(unittest.TestCase):
+ """Test the MHonArc archiver."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ # Create a fake mailing list and message object.
+ self._msg = mfs("""\
+To: test@example.com
+From: anne@example.com
+Subject: Testing the test list
+Message-ID: <ant>
+Message-ID-Hash: MS6QLWERIJLGCRF44J7USBFDELMNT2BW
+
+Tests are better than no tests
+but the water deserves to be swum.
+""")
+ with transaction():
+ self._mlist = create_list('test@example.com')
+ tempdir = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, tempdir)
+ # Here's the command to execute our fake MHonArc process.
+ shutil.copy(
+ resource_filename('mailman.archiving.tests', 'fake_mhonarc.py'),
+ tempdir)
+ self._output_file = os.path.join(tempdir, 'output.txt')
+ command = '{} {} {}'.format(
+ sys.executable,
+ os.path.join(tempdir, 'fake_mhonarc.py'),
+ self._output_file)
+ # Write an external configuration file which points the command at our
+ # fake MHonArc process.
+ self._cfg = os.path.join(tempdir, 'mhonarc.cfg')
+ with open(self._cfg, 'w', encoding='utf-8') as fp:
+ print("""\
+[general]
+base_url: http://$hostname/archives/$fqdn_listname
+command: {command}
+""".format(command=command), file=fp)
+
+ def test_mhonarc(self):
+ # The archiver properly sends stdin to the subprocess.
+ with configuration('archiver.mhonarc',
+ configuration=self._cfg,
+ enable='yes'):
+ MHonArc().archive_message(self._mlist, self._msg)
+ with open(self._output_file, 'r', encoding='utf-8') as fp:
+ results = fp.read().splitlines()
+ self.assertEqual(results[0], '<ant>')
+ self.assertEqual(results[1], 'MS6QLWERIJLGCRF44J7USBFDELMNT2BW')
diff --git a/src/mailman/archiving/tests/test_prototype.py b/src/mailman/archiving/tests/test_prototype.py
index 797f65584..739586482 100644
--- a/src/mailman/archiving/tests/test_prototype.py
+++ b/src/mailman/archiving/tests/test_prototype.py
@@ -47,7 +47,7 @@ class TestPrototypeArchiver(unittest.TestCase):
layer = ConfigLayer
def setUp(self):
- # Create a fake mailing list and message object
+ # Create a fake mailing list and message object.
self._msg = mfs("""\
To: test@example.com
From: anne@example.com
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst
index 0d46faf59..341f22f0a 100644
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -28,6 +28,8 @@ Bugs
Given by Abhilash Raj. (Closes #115)
* `mailman` command with no subcommand now prints the help text. Given by
Abhilash Raj. (Closes #137)
+ * The MHonArc archiver must set stdin=PIPE when calling the subprocess.
+ Given by Walter Doekes.
Configuration
-------------