From: Oleg Broytman Date: Wed, 26 Feb 2014 16:11:32 +0000 (+0400) Subject: Version 2.3.8 X-Git-Tag: v2.3.8^0 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=fa51f1e417da0f8d66649ebe67c78a58b1b88eae;p=mimedecode.git Version 2.3.8 Add option --remove-params=header to remove all parameters from the header. --- diff --git a/ANNOUNCE b/ANNOUNCE index bbcf602..de1e4e1 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -22,6 +22,10 @@ RFC822 message it is decoded as one part. If it is a MIME message with multiple parts ("attachments") all parts are decoded. Decoding can be controlled by command-line options. +WHAT'S NEW in version 2.3.8 (2014-02-26) + + Add option --remove-params=header to remove all parameters from the header. + WHAT'S NEW in version 2.3.7 (2014-02-23) Add option -r to remove headers and option -R to remove header's parameters. @@ -76,9 +80,8 @@ WHERE TO GET Recommends: configured mailcap database. - Documentation (also included in the package): - http://phdru.name/Software/Python/mimedecode.txt - + Documentation: http://phdru.name/Software/Python/mimedecode.txt + (also included in the package in the html and man formats): AUTHOR Oleg Broytman diff --git a/mimedecode.docbook b/mimedecode.docbook index 83b0e54..382fba2 100644 --- a/mimedecode.docbook +++ b/mimedecode.docbook @@ -59,6 +59,9 @@ + + + @@ -256,6 +259,16 @@ + + --remove-params=header + + + Add the header to a list of headers from which all parameters will + be removed; initially the list is empty. + + + + -b mask diff --git a/mimedecode.py b/mimedecode.py index dcf307c..1e5b18b 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -18,7 +18,7 @@ Broytman mimedecode.py version %s, %s def usage(code=0, errormsg=''): version(0) sys.stdout.write("""\ -Usage: %s [-h|--help] [-V|--version] [-cCDP] [-H|--host=hostname] [-f charset] [-d header] [-p header:param] [-r header] [-R header:param] [-beit mask] [-o output_file] [input_file [output_file]] +Usage: %s [-h|--help] [-V|--version] [-cCDP] [-H|--host=hostname] [-f charset] [-d header] [-p header:param] [-r header] [-R header:param] [--remove-params=header] [-beit mask] [-o output_file] [input_file [output_file]] """ % me) if errormsg: sys.stderr.write(errormsg + '\n') @@ -100,6 +100,15 @@ def decode_headers(msg): for header in gopts.remove_headers: del msg[header] + for header in gopts.remove_all_params: + value = msg[header] + if value is None: + continue + if ';' not in value: + continue + del msg[header] + msg[header] = value.split(';')[0].strip() + for header, param in gopts.remove_header_params: msg.del_param(param, header) @@ -291,6 +300,8 @@ class GlobalOptions: remove_headers = [] # A list of headers parameters to remove remove_header_params = [] + # A list of headers to be stripped of all parameters + remove_all_params = [] totext_mask = [] # A list of content-types to decode binary_mask = [] # A list to pass through @@ -309,7 +320,7 @@ def get_opt(): try: options, arguments = getopt(sys.argv[1:], 'hVcCDPH:f:d:p:r:R:b:e:i:t:o:', - ['help', 'version', 'host']) + ['help', 'version', 'host=', 'remove-params=']) except GetoptError: usage(1) @@ -338,6 +349,8 @@ def get_opt(): gopts.remove_headers.append(value) elif option == '-R': gopts.remove_header_params.append(value.split(':', 1)) + elif option == '--remove-params': + gopts.remove_all_params.append(value) elif option == '-t': gopts.totext_mask.append(value) elif option == '-b': diff --git a/mimedecode_version.py b/mimedecode_version.py index eebbcdd..eff132e 100644 --- a/mimedecode_version.py +++ b/mimedecode_version.py @@ -1,4 +1,4 @@ -__version__ = "2.3.7" +__version__ = "2.3.8" __author__ = "Oleg Broytman " __copyright__ = "Copyright (C) 2001-2014 PhiloSoft Design" __license__ = "GNU GPL" diff --git a/test/expected/msg_18-1.txt b/test/expected/msg_18-1.txt new file mode 100644 index 0000000..28af17d --- /dev/null +++ b/test/expected/msg_18-1.txt @@ -0,0 +1,7 @@ +From test Sat Feb 1 00:00:00 2014 +Content-Transfer-Encoding: 7bit +X-Foobar-Spoink-Defrobnit: wasnipoop +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +X-MIME-Autoconverted: from us-ascii to utf-8 by test id mimedecode.py + diff --git a/test/test_all b/test/test_all index f08ff8c..669d6b3 100755 --- a/test/test_all +++ b/test/test_all @@ -43,6 +43,7 @@ test_file msg_15.txt msg_15-1.txt -b text/html test_file msg_15.txt msg_15-2.txt -i text/html test_file msg_22.txt msg_22-1.txt -r content-id test_file msg_29.txt msg_29-1.txt -R Content-Type:title +test_file msg_18.txt msg_18-1.txt --remove-params=X-Foobar-Spoink-Defrobnit if [ "$RC" -eq 0 ]; then echo "All tests passed!"