From 93b627c389e98f0ef7347035ee75a8603b6dd866 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 23 Feb 2014 20:13:49 +0400 Subject: [PATCH] Add option -r to remove headers --- mimedecode.docbook | 13 +++++++++++++ mimedecode.py | 10 +++++++++- test/expected/msg_22-1.txt | Bin 0 -> 1902 bytes test/test_all | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/expected/msg_22-1.txt 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 0000000000000000000000000000000000000000..0d58be1347ef26e691de16fdbc6ee49e8e4ea42b GIT binary patch literal 1902 zcmZ=O%Fk6ONi8l>2u>_fa7#^6P%u<5Ft7q61tSAP6E5G(+*IAL)S}|d{5&fKLp=j7 z-_+vb#Pn2M&lD>Kn?wUs0|P@#1EVDKG{a!kR7;0wLt_&?3llv<3u8S)V~bcj zE|^3)V1t_WSQagL=W`N{ctWvN9aslZT8 z14T<|v2J2Az}qUBIGP%mn3|X) zNhBAgCYIzE0p-k1oJ`zIT$Q+B7Pw><7vvXbmVlE{Vo6D2az-vN5`jUInUjiX7ff47 zQDRr2d2!MD8L78cZ9C}nbIqj$p30W}_f)Q4y||^NY@*3p z)7YKq(bA!1mh3u*6#TW8PrmB-M(g~IH768qMLl?T;Ai}VKm4QKou|b57fw{4-xo=8toL%5C!vl|51p9piIF36pzR}EB)b;-+Imre` z^uVJJoJEn771k64OIVoc2Q?iY+6zgEFyo0%R4|Qr^4s7^HgiGA=Km1}d0?7kg``9V zC}3n_W?^Mx=iubx1}fMpz`(@F%*@2X%*x8b!VtaKRb_(9MBkDL3nv#QGar_o^4rOM zpT8E<<(1}KliWT36c?oOs~(@WT4dVABc0ZFWA+5T`>Z5k?8z{73ByU7G>6vZ6Spnu z3;X?uckLEk(=Qi}OwfyqUU~kO(8GHXSMytLR)(caa!KBFEs-Z!$G3RLvHL843O?4( z@7x-zxMjBT%G2qhzwXbj^|Ovx`*h;l#4c5%lOjQrruCe=s8Og`Y;o_wc9PQAuqtSE Hb-B0zUy4z! literal 0 HcmV?d00001 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!" -- 2.39.5