]> git.phdru.name Git - mimedecode.git/blobdiff - mimedecode.py
Create the directory for the output files
[mimedecode.git] / mimedecode.py
index 392e70774e5f1cb2537c5b94fa87906a71470f22..c1731d6336c5ab8eff9e5928a61a9cce1181ddc2 100755 (executable)
@@ -396,7 +396,16 @@ def decode_message(msg):
 
 
 def open_output_file(filename):
-    return open(os.path.join(g.destination_dir, filename), 'w')
+    fullpath = os.path.abspath(os.path.join(g.destination_dir, filename))
+    full_dir = os.path.dirname(fullpath)
+    create = not os.path.isdir(full_dir)
+    if create:
+        os.makedirs(full_dir)
+    try:
+        return open(fullpath, 'w')
+    except:
+        if create:
+            os.removedirs(full_dir)
 
 
 class GlobalOptions: