From: Oleg Broytman Date: Sun, 23 Feb 2014 16:13:49 +0000 (+0400) Subject: Add option -r to remove headers X-Git-Tag: v2.3.7~2 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=93b627c389e98f0ef7347035ee75a8603b6dd866;p=mimedecode.git Add option -r to remove headers --- diff --git a/mimedecode.docbook b/mimedecode.docbook index 8fda9a2..0605fa8 100644 --- a/mimedecode.docbook +++ b/mimedecode.docbook @@ -53,6 +53,9 @@ + + + @@ -228,6 +231,16 @@ command-line options. + + -r header + + + Add the header to a list of headers to remove completely; initially + the list is empty. + + + + -b mask diff --git a/mimedecode.py b/mimedecode.py index 569559b..c3e3ecf 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -103,6 +103,9 @@ def decode_headers(msg): for header, param in gopts.decode_header_params: decode_header_param(msg, header, param) + for header in gopts.remove_headers: + del msg[header] + def set_header(msg, header, value): "Replace header" @@ -281,6 +284,9 @@ class GlobalOptions: ("Content-Disposition", "filename"), ] + # A list of headers to remove + remove_headers = [] + totext_mask = [] # A list of content-types to decode binary_mask = [] # A list to pass through ignore_mask = [] # Ignore (skip, do not decode and do not include into output) @@ -296,7 +302,7 @@ def get_opt(): from getopt import getopt, GetoptError try: - options, arguments = getopt(sys.argv[1:], 'hVcCDPH:f:d:p:b:e:i:t:o:', + options, arguments = getopt(sys.argv[1:], 'hVcCDPH:f:d:p:r:b:e:i:t:o:', ['help', 'version', 'host']) except GetoptError: usage(1) @@ -322,6 +328,8 @@ def get_opt(): gopts.decode_header_params.append(value.split(':', 1)) elif option == '-P': gopts.decode_header_params = [] + elif option == '-r': + gopts.remove_headers.append(value) elif option == '-t': gopts.totext_mask.append(value) elif option == '-b': diff --git a/test/expected/msg_22-1.txt b/test/expected/msg_22-1.txt new file mode 100644 index 0000000..0d58be1 Binary files /dev/null and b/test/expected/msg_22-1.txt differ diff --git a/test/test_all b/test/test_all index 3de6ec7..19198b1 100755 --- a/test/test_all +++ b/test/test_all @@ -41,6 +41,7 @@ done 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 if [ "$RC" -eq 0 ]; then echo "All tests passed!"