X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=mimedecode.py;h=c1731d6336c5ab8eff9e5928a61a9cce1181ddc2;hb=41e92ab685cbcf842d1c4f33b8b29f94193938ed;hp=392e70774e5f1cb2537c5b94fa87906a71470f22;hpb=b92e86cc18ad38cd2c8db1a3217ca2fed1c50c2f;p=mimedecode.git diff --git a/mimedecode.py b/mimedecode.py index 392e707..c1731d6 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -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: