]> git.phdru.name Git - mimedecode.git/commitdiff
open_output_file
authorOleg Broytman <phd@phdru.name>
Thu, 13 Mar 2014 21:17:02 +0000 (01:17 +0400)
committerOleg Broytman <phd@phdru.name>
Thu, 13 Mar 2014 21:17:02 +0000 (01:17 +0400)
mimedecode.py

index 01f650563060eb085b6811295a8ee8ce267c2744..392e70774e5f1cb2537c5b94fa87906a71470f22 100755 (executable)
@@ -279,7 +279,7 @@ def _save_message(msg, outstring, save_headers=False, save_body=False):
 
     global output
     save_output = output
-    outfile = open(os.path.join(g.destination_dir, fname), 'w')
+    outfile = open_output_file(fname)
     output = outfile.write
     if save_headers:
         output_headers(msg)
@@ -395,6 +395,10 @@ def decode_message(msg):
         output(msg.as_string())
 
 
+def open_output_file(filename):
+    return open(os.path.join(g.destination_dir, filename), 'w')
+
+
 class GlobalOptions:
     from m_lib.defenc import default_encoding
     recode_charset = 1 # recode charset of message body
@@ -521,7 +525,7 @@ if __name__ == "__main__":
         g.input_filename = '-'
         infile = sys.stdin
         if g.output_filename:
-            outfile = open(os.path.join(g.destination_dir, g.output_filename), 'w')
+            outfile = open_output_file(g.output_filename)
         else:
             g.output_filename = '-'
             outfile = sys.stdout
@@ -534,7 +538,7 @@ if __name__ == "__main__":
             infile = open(arguments[0], 'r')
         if la == 1:
             if g.output_filename:
-                outfile = open(os.path.join(g.destination_dir, g.output_filename), 'w')
+                outfile = open_output_file(g.output_filename)
             else:
                 g.output_filename = '-'
                 outfile = sys.stdout
@@ -546,7 +550,7 @@ if __name__ == "__main__":
                 outfile = sys.stdout
             else:
                 g.output_filename = arguments[1]
-                outfile = open(os.path.join(g.destination_dir, g.output_filename), 'w')
+                outfile = open_output_file(g.output_filename)
     else:
         usage(1, 'Too many arguments')