X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=mimedecode.py;h=392e70774e5f1cb2537c5b94fa87906a71470f22;hb=b92e86cc18ad38cd2c8db1a3217ca2fed1c50c2f;hp=fdea039d04f0fc6ee9716137d86dc3763f72e0d4;hpb=b068be834a5be5407c5ab2cf18910bc03fddc9ef;p=mimedecode.git diff --git a/mimedecode.py b/mimedecode.py index fdea039..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') @@ -565,7 +569,7 @@ if __name__ == "__main__": msg = email.message_from_file(infile) for header, value in g.set_header_value: - msg[header] = value + set_header(msg, header, value) for header, param, value in g.set_header_param: if header in msg: