]> git.phdru.name Git - mimedecode.git/commitdiff
Allow * and exceptions for -p in the parameters lists
authorOleg Broytman <phd@phdru.name>
Sat, 8 Mar 2014 15:36:54 +0000 (19:36 +0400)
committerOleg Broytman <phd@phdru.name>
Sat, 8 Mar 2014 15:36:54 +0000 (19:36 +0400)
Allow * and exceptions for -p in the parameters lists:
-p h1,h2,h3:*,-p1,-p2,-p3
-p *,-h1,-h2,-h3:*,-p1,-p2,-p3

ANNOUNCE
TODO
mimedecode.docbook
mimedecode.py
test/test_all

index e23ea9beb7c7881049f0f2d5cd688f8bb35e39ab..d13c3305ce70869a30e15b49dd11ca93fb7674d5 100644 (file)
--- 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 da13a02ef28cdd05db98de44a08739d2247f6db4..863f92c03ff16675840f5eced61905eb4203f7af 100644 (file)
--- 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.
index f9650bd26891a9afaf85036f1090a9e4ce02c17a..0346b2bd36b9c80df81eef5b6932eded46ebcbf3 100644 (file)
       <arg choice="opt">
         <option>-p header1[,header2,header3,...]:param1[,param2,param3,...]</option>
       </arg>
+      <arg choice="opt">
+        <option>-p *[,-header1,-header2,-header3,...]:param1[,param2,param3,...]</option>
+        <option>-p header1[,header2,header3,...]:*[,-param1,-param2,-param3,...]</option>
+        <option>-p *[,-header1,-header2,-header3,...]:*[,-param1,-param2,-param3,...]</option>
+      </arg>
       <arg choice="opt">
          <option>-r header</option>
       </arg>
       </listitem>
    </varlistentry>
 
+   <varlistentry>
+      <term>-p header1[,header2,header3,...]:*[,-param1,-param2,-param3,...]</term>
+      <listitem>
+         <para>
+           Decode all parameters except listed for the given list of headers.
+         </para>
+      </listitem>
+   </varlistentry>
+
+   <varlistentry>
+      <term>-p *[,-header1,-header2,-header3,...]:*[,-param1,-param2,-param3,...]</term>
+      <listitem>
+         <para>
+           Decode all parameters except listed for all headers (except listed).
+         </para>
+      </listitem>
+   </varlistentry>
+
    <varlistentry>
       <term>-P</term>
       <listitem>
index 6d4c7ea8cef6856844935337d0798eff27c61da1..f3362cf824121c218daf2b8a9833f7281b663705 100755 (executable)
@@ -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):
index 8c59da558550d5b24b6201bc16a442edbda4d048..7f6c65c2dde8bdd6b99b8d057aa865ae2dc03cbf 100755 (executable)
@@ -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!"