From: Oleg Broytman Date: Sat, 8 Mar 2014 13:41:32 +0000 (+0400) Subject: Change option -d to decode all headers with exceptions X-Git-Tag: v2.4.0~11 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=68284da58382c25f607b161f95a7baf05d178bdc;p=mimedecode.git Change option -d to decode all headers with exceptions Change option -d to decode all headers and accept a list of exceptions: -d *,-h1,-h2,... --- diff --git a/ANNOUNCE b/ANNOUNCE index dfca45c..662f947 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -28,6 +28,9 @@ WHAT'S NEW in version 2.4.0 (2014-03-??) Change option -d to accept a comma-separated list of headers: -d h1,h2,h3,... + Change option -d to decode all headers and accept a list of exceptions: +-d *,-h1,-h2,... + Add ChangeLog. WHAT'S NEW in version 2.3.8 (2014-02-26) diff --git a/TODO b/TODO index fae378b..4428a0a 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,3 @@ -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 Allow * and exceptions: diff --git a/mimedecode.docbook b/mimedecode.docbook index 28af4ac..4cbd688 100644 --- a/mimedecode.docbook +++ b/mimedecode.docbook @@ -50,6 +50,9 @@ + + + @@ -209,6 +212,25 @@ + + -d *[,-header1,-header2,-header3...] + + + This variant completely changes headers decoding. First, the list of + headers to decode is cleared. Then all the headers are decoded + except the given list of exceptions (headers listed with '-'). In + 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'. + + + + -D diff --git a/mimedecode.py b/mimedecode.py index 82f2d26..23493d4 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[,header2,header3...]] [-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 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') @@ -114,8 +114,15 @@ def decode_headers(msg): msg.del_param(param, header) for header_list in gopts.decode_headers: - for header in header_list.split(','): - decode_header(msg, header) + header_list = header_list.split(',') + if header_list[0] == '*': # Decode all headers except listed + header_list = [h[1:].lower() for h in header_list[1:] if h[0]=='-'] + for header in msg.keys(): + if header.lower() not in header_list: + decode_header(msg, header) + else: # Decode listed hiders + for header in header_list: + decode_header(msg, header) for header, param in gopts.decode_header_params: decode_header_param(msg, header, param) @@ -340,6 +347,8 @@ def get_opt(): elif option == '-f': gopts.default_encoding = value elif option == '-d': + if value.startswith('*'): + gopts.decode_headers = [] gopts.decode_headers.append(value) elif option == '-D': gopts.decode_headers = [] diff --git a/test/test_all b/test/test_all index bf826c6..25f8183 100755 --- a/test/test_all +++ b/test/test_all @@ -40,6 +40,8 @@ for f in input/*.txt; do done test_file msg_03.txt msg_03-1.txt -D -d From,To,Subject +test_file msg_03.txt msg_03-1.txt -d '*,-cc' +test_file msg_03.txt msg_03-1.txt -d \*,From,To,Subject,-cc 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