From 0a403f7adfdd3a7fcc019b84affa602e8e934169 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sat, 8 Mar 2014 19:36:54 +0400 Subject: [PATCH] Allow * and exceptions for -p in the parameters lists Allow * and exceptions for -p in the parameters lists: -p h1,h2,h3:*,-p1,-p2,-p3 -p *,-h1,-h2,-h3:*,-p1,-p2,-p3 --- ANNOUNCE | 4 +++- TODO | 23 +++++++---------------- mimedecode.docbook | 23 +++++++++++++++++++++++ mimedecode.py | 25 +++++++++++++++++++++---- test/test_all | 2 ++ 5 files changed, 56 insertions(+), 21 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index e23ea9b..d13c330 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -34,8 +34,10 @@ WHAT'S NEW in version 2.4.0 (2014-03-??) Change option -p to accept lists of headers and parameters: -p h1,h2,h3,..:p1,p2,p3,.. - Allow * and exceptions for -p in the headers list: + Allow * and exceptions for -p in the headers and parameters lists: -p *,-h1,-h2,-h3:p1,p2,p3 +-p h1,h2,h3:*,-p1,-p2,-p3 +-p *,-h1,-h2,-h3:*,-p1,-p2,-p3 Add ChangeLog. diff --git a/TODO b/TODO index da13a02..863f92c 100644 --- a/TODO +++ b/TODO @@ -1,15 +1,3 @@ -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 - - -Publish docs in html format. - - -Release 2.4.0. - - Change option -r to accept a list of headers: -r h1,h2,h3,... @@ -28,7 +16,10 @@ Allow * and exceptions: Remove option --remove-params. -Release 2.5.0. +Publish docs in html format. + + +Release 2.4.0. Add option -s to save decoded headers/bodies/messages of parts to files. @@ -40,7 +31,7 @@ Add an option -B to skip content-transfer-decoding binary attachments (leave it as base64 or such). -Release 2.6.0. +Release 2.5.0. Allow -d and -p accept shell-like patterns and/or regular expressions: @@ -54,7 +45,7 @@ nothing. Never touch multipart/encrypted and multipart/signed. -Release 2.7.0. +Release 2.6.0. Extend options -eIi to multipart subparts. @@ -63,4 +54,4 @@ Extend options -eIi to multipart subparts. Add an option to convert dates to the current locate and timezone. -Release 2.8.0. +Release 2.7.0. diff --git a/mimedecode.docbook b/mimedecode.docbook index f9650bd..0346b2b 100644 --- a/mimedecode.docbook +++ b/mimedecode.docbook @@ -56,6 +56,11 @@ + + + + + @@ -264,6 +269,24 @@ + + -p header1[,header2,header3,...]:*[,-param1,-param2,-param3,...] + + + Decode all parameters except listed for the given list of headers. + + + + + + -p *[,-header1,-header2,-header3,...]:*[,-param1,-param2,-param3,...] + + + Decode all parameters except listed for all headers (except listed). + + + + -P diff --git a/mimedecode.py b/mimedecode.py index 6d4c7ea..f3362cf 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -130,16 +130,33 @@ def decode_headers(msg): for header_list, param_list in gopts.decode_header_params: header_list = header_list.split(',') param_list = param_list.split(',') + decode_all_params = param_list[0] == '*' # Decode all params except listed + if decode_all_params: + param_list = _get_exceptions(param_list) if header_list[0] == '*': # Decode for all headers except listed header_list = _get_exceptions(header_list) for header in msg.keys(): if header.lower() not in header_list: - for param in param_list: - decode_header_param(msg, header, param) + if decode_all_params: + params = msg.get_params(header=header) + if params: + for param, value in params: + if param not in param_list: + decode_header_param(msg, header, param) + else: + for param in param_list: + decode_header_param(msg, header, param) else: # Decode for listed headers for header in header_list: - for param in param_list: - decode_header_param(msg, header, param) + if decode_all_params: + params = msg.get_params(header=header) + if params: + for param, value in params: + if param not in param_list: + decode_header_param(msg, header, param) + else: + 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 8c59da5..7f6c65c 100755 --- a/test/test_all +++ b/test/test_all @@ -49,6 +49,8 @@ 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 test_file msg_22.txt msg_22.txt -P -p \*:name,filename +test_file msg_22.txt msg_22.txt -P -p Content-Type,Content-Disposition:\* +test_file msg_22.txt msg_22.txt -P -p '*,-Content-Id:*,-x-mac-type' if [ "$RC" -eq 0 ]; then echo "All tests passed!" -- 2.39.2