From b92e86cc18ad38cd2c8db1a3217ca2fed1c50c2f Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Fri, 14 Mar 2014 01:17:02 +0400 Subject: [PATCH] open_output_file --- mimedecode.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mimedecode.py b/mimedecode.py index 01f6505..392e707 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -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') -- 2.39.5