From: Jelte Fennema-Nio Date: Mon, 16 Jun 2025 10:27:31 +0000 (+0200) Subject: Allow passing filenames to --mbox that contain parentheses X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=65c446213213eecd5bd704c306ee8a8e07a25cff;p=pgarchives.git Allow passing filenames to --mbox that contain parentheses Without this you would get an error like this: Failed to parse mbox: b'/bin/sh: 1: Syntax error: "(" unexpected\n' This especially matters when loading files downloaded with a browser, since those often contain (1) or (2) if a file with the same name was downloaded earlier. --- diff --git a/loader/lib/mbox.py b/loader/lib/mbox.py index 278fd6c..f2c1d2f 100644 --- a/loader/lib/mbox.py +++ b/loader/lib/mbox.py @@ -16,11 +16,13 @@ class MailboxBreakupParser(object): self.EOF = False if fn.endswith(".gz"): - cat = "zcat" + file_stream = Popen(['zcat', fn], stdout=PIPE).stdout else: - cat = "cat" - cmd = "%s %s | formail -s /bin/sh -c 'cat && echo %s'" % (cat, fn, SEPARATOR) - self.pipe = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) + file_stream = open(fn, 'rb') + formail_cmd = "formail -s /bin/sh -c 'cat && echo %s'" % (SEPARATOR,) + self.pipe = Popen(formail_cmd, shell=True, stdin=file_stream, stdout=PIPE, stderr=PIPE) + # Allow self.pipe to receive a SIGPIPE if zcat exits. + file_stream.close() def returncode(self): self.pipe.wait()