From 9b7a47dbf92abf9bf6e4226ad4fe7da470c8da5f Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Sat, 22 Apr 2017 15:39:13 -0700 Subject: Enhance Switchboard.finish() to look for .pck if no .bak. --- src/mailman/core/switchboard.py | 7 +++++++ src/mailman/core/tests/test_switchboard.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'src') diff --git a/src/mailman/core/switchboard.py b/src/mailman/core/switchboard.py index 315d564f3..e9e5e95f1 100644 --- a/src/mailman/core/switchboard.py +++ b/src/mailman/core/switchboard.py @@ -167,6 +167,13 @@ class Switchboard: def finish(self, filebase, preserve=False): """See `ISwitchboard`.""" bakfile = os.path.join(self.queue_directory, filebase + '.bak') + # It is possible for a queue entry to be created by a non-Mailman user + # and not be readable by the Mailman user:group. If this happens, we + # get here and the file is a .pck rather than a .bak. + pckfile = os.path.join(self.queue_directory, filebase + '.pck') + if not os.path.isfile(bakfile) and os.path.isfile(pckfile): + # We have a .pck and not a .bak so switch the name for the next. + bakfile = pckfile try: if preserve: bad_dir = config.switchboards['bad'].queue_directory diff --git a/src/mailman/core/tests/test_switchboard.py b/src/mailman/core/tests/test_switchboard.py index 5303abb9b..7fe527ee1 100644 --- a/src/mailman/core/tests/test_switchboard.py +++ b/src/mailman/core/tests/test_switchboard.py @@ -17,6 +17,7 @@ """Switchboard tests.""" +import os import unittest from mailman.config import config @@ -51,3 +52,22 @@ Message-ID: traceback = error_log.read().splitlines() self.assertEqual(traceback[1], 'Traceback (most recent call last):') self.assertEqual(traceback[-1], 'OSError: Oops!') + + def test_no_bak_but_pck(self): + # if there is no .bak file but a .pck with the same filebase, + # .finish() should handle the .pck. + msg = mfs("""\ +From: anne@example.com +To: test@example.com +Message-ID: + +""") + switchboard = config.switchboards['shunt'] + # Enqueue the message. + filebase = switchboard.enqueue(msg) + # Now call .finish() without first dequeueing. + switchboard.finish(filebase, preserve=True) + # And ensure the file got preserved. + bad_dir = config.switchboards['bad'].queue_directory + psvfile = os.path.join(bad_dir, filebase + '.psv') + self.assertTrue(os.path.isfile(psvfile)) -- cgit v1.2.3-70-g09d2