]> git.phdru.name Git - mimedecode.git/commitdiff
Add option -r to remove headers
authorOleg Broytman <phd@phdru.name>
Sun, 23 Feb 2014 16:13:49 +0000 (20:13 +0400)
committerOleg Broytman <phd@phdru.name>
Sun, 23 Feb 2014 16:13:49 +0000 (20:13 +0400)
mimedecode.docbook
mimedecode.py
test/expected/msg_22-1.txt [new file with mode: 0644]
test/test_all

index 8fda9a21cb1510165bd7b48fda1a846d05021847..0605fa84da98e3845df8d51d3619b7eed7dbe7cf 100644 (file)
@@ -53,6 +53,9 @@
       <arg choice="opt">
          <option>-p header:param</option>
       </arg>
+      <arg choice="opt">
+         <option>-r header</option>
+      </arg>
       <arg choice="opt">
          <option>-beit mask</option>
       </arg>
@@ -228,6 +231,16 @@ command-line options.
       </listitem>
    </varlistentry>
 
+   <varlistentry>
+      <term>-r header</term>
+      <listitem>
+         <para>
+            Add the header to a list of headers to remove completely; initially
+            the list is empty.
+         </para>
+      </listitem>
+   </varlistentry>
+
    <varlistentry>
       <term>-b mask</term>
       <listitem>
index 569559b19e722e11de98ece1daaec3063fe51521..c3e3ecffc13fba23137cdc8c955ab2bffe0f861b 100755 (executable)
@@ -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 (file)
index 0000000..0d58be1
Binary files /dev/null and b/test/expected/msg_22-1.txt differ
index 3de6ec74fb0daf91ff740250d7d3a1c261693640..19198b1b28831306312134b0927bddc92fc53efb 100755 (executable)
@@ -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!"