Allow passing filenames to --mbox that contain parentheses
authorJelte Fennema-Nio <github-tech@jeltef.nl>
Mon, 16 Jun 2025 10:27:31 +0000 (12:27 +0200)
committerMagnus Hagander <magnus@hagander.net>
Mon, 16 Jun 2025 10:27:31 +0000 (12:27 +0200)
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.

loader/lib/mbox.py

index 278fd6c0f8e0f5aebc2590dd0951c25dfdb7f299..f2c1d2f0d9ac46be87e7b5570e3723ba12a83a43 100644 (file)
@@ -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()