From: Oleg Broytman Date: Sat, 8 Mar 2014 14:33:18 +0000 (+0400) Subject: Change option -p to accept lists X-Git-Tag: v2.4.0~10 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=132782e4926381f746dd9ea6b03e3feaaf52579a;p=mimedecode.git Change option -p to accept lists Change option -p to accept lists of headers and parameters: -p h1,h2,h3,..:p1,p2,p3,.. --- diff --git a/ANNOUNCE b/ANNOUNCE index 662f947..23d113c 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -31,6 +31,9 @@ WHAT'S NEW in version 2.4.0 (2014-03-??) Change option -d to decode all headers and accept a list of exceptions: -d *,-h1,-h2,... + Change option -p to accept lists of headers and parameters: +-p h1,h2,h3,..:p1,p2,p3,.. + Add ChangeLog. WHAT'S NEW in version 2.3.8 (2014-02-26) diff --git a/TODO b/TODO index 4428a0a..da13a02 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,4 @@ -Change option -p to accept lists of headers and parameters: --p h1,h2,h3:p1,p2,p3 -Allow * and exceptions: +Allow * and exceptions for -p: -p h1,h2,h3:*,-p1,-p2,-p3 -p *,-h1,-h2,-h3:p1,p2,p3 -p *,-h1,-h2,-h3:*,-p1,-p2,-p3 diff --git a/mimedecode.docbook b/mimedecode.docbook index 4cbd688..d98db68 100644 --- a/mimedecode.docbook +++ b/mimedecode.docbook @@ -54,7 +54,7 @@ - + @@ -137,6 +137,13 @@ + + + Please be warned that in the following options asterisk is a shell + metacharacter and should be escaped or quoted. Either write -d \*,-h1,-h2 + or -d '*,-h1,-h2' or such. + + OPTIONS @@ -222,12 +229,6 @@ this mode it would be meaningless to give more than one -d options but the program doesn't enforce it. - - - Please be warned that the asterisk is a shell metacharacter and - should be escaped or quoted. Either write -d \*,-h1,-h2 or -d - '*,-h1,-h2'. - @@ -241,13 +242,13 @@ - -p header:param + -p header1[,header2,header3,...]:param1[,param2,param3,...] - Add the pair (header, param) to a list of headers parameters to - decode; initially the list contains header "Content-Type", - parameter "name" and header "Content-Disposition", parameter - "filename". + Add the parameters(s) to a list of headers parameters to decode; + the parameters will be decoded only for the given header(s). + Initially the list contains header "Content-Type", parameter "name"; + and header "Content-Disposition", parameter "filename". diff --git a/mimedecode.py b/mimedecode.py index 23493d4..0e01572 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 header1[,h2,...]|*[,-h1,...]] [-p header:param] [-r header] [-R header:param] [--remove-params=header] [-beit mask] [-o output_file] [input_file [output_file]] +Usage: %s [-h|--help] [-V|--version] [-cCDP] [-H|--host=hostname] [-f charset] [-d header1[,h2,...]|*[,-h1,...]] [-p header1[,h2,h3,...]:param1[,p2,p3,...]] [-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') @@ -124,8 +124,12 @@ def decode_headers(msg): for header in header_list: decode_header(msg, header) - for header, param in gopts.decode_header_params: - decode_header_param(msg, header, param) + for header_list, param_list in gopts.decode_header_params: + header_list = header_list.split(',') + param_list = param_list.split(',') + for header in header_list: + for param in param_list: + decode_header_param(msg, header, param) def set_header(msg, header, value): diff --git a/test/test_all b/test/test_all index 25f8183..f61c63a 100755 --- a/test/test_all +++ b/test/test_all @@ -47,6 +47,7 @@ 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 +test_file msg_22.txt msg_22.txt -P -p Content-Type,Content-Disposition:name,filename if [ "$RC" -eq 0 ]; then echo "All tests passed!"