]> git.phdru.name Git - mimedecode.git/commitdiff
Change option -r to accept a list of headers; * is allowed
authorOleg Broytman <phd@phdru.name>
Sat, 8 Mar 2014 16:26:10 +0000 (20:26 +0400)
committerOleg Broytman <phd@phdru.name>
Sat, 8 Mar 2014 16:39:59 +0000 (20:39 +0400)
Change option -r to accept a list of headers: -r h1,h2,h3,...

Asterisk is allowed to remove all headers and accept a list of exceptions:
-r *,-h1,-h2,...

ANNOUNCE
TODO
mimedecode.docbook
mimedecode.py
test/expected/msg_16-1.txt [new file with mode: 0644]
test/expected/msg_16-2.txt [new file with mode: 0644]
test/test_all

index d13c3305ce70869a30e15b49dd11ca93fb7674d5..923a772a58b653f99e7445c0196abf37def5452b 100644 (file)
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -39,6 +39,12 @@ WHAT'S NEW in version 2.4.0 (2014-03-??)
 -p h1,h2,h3:*,-p1,-p2,-p3
 -p *,-h1,-h2,-h3:*,-p1,-p2,-p3
 
+   Change option -r to accept a list of headers: -r h1,h2,h3,...
+
+   Change option -r to remove all headers and accept a list of exceptions:
+-r *,-h1,-h2,...
+
+
    Add ChangeLog.
 
 WHAT'S NEW in version 2.3.8 (2014-02-26)
diff --git a/TODO b/TODO
index 863f92c03ff16675840f5eced61905eb4203f7af..a46034ac068996f2f792d89002e1fb328ba49579 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,10 +1,3 @@
-Change option -r to accept a list of headers: -r h1,h2,h3,...
-
-
-Change option -r to remove all headers and accept a list of exceptions:
--r *,-h1,-h2,...
-
-
 Change option -R to accept lists of headers and parameters:
 -R h1,h2,h3:p1,p2,p3
 Allow * and exceptions:
index 0346b2bd36b9c80df81eef5b6932eded46ebcbf3..75ec36798b496bf80a167002f8ee25719b07043f 100644 (file)
         <option>-p *[,-header1,-header2,-header3,...]:*[,-param1,-param2,-param3,...]</option>
       </arg>
       <arg choice="opt">
-         <option>-r header</option>
+         <option>-r header1[,header2,header3...]</option>
+      </arg>
+      <arg choice="opt">
+         <option>-r *[,-header1,-header2,-header3...]</option>
       </arg>
       <arg choice="opt">
          <option>-R header:param</option>
    </varlistentry>
 
    <varlistentry>
-      <term>-r header</term>
+      <term>-r header1[,header2,header3...]</term>
+      <listitem>
+         <para>
+            Add the header(s) to a list of headers to remove completely;
+            initially the list is empty.
+         </para>
+      </listitem>
+   </varlistentry>
+
+   <varlistentry>
+      <term>-r *[,-header1,-header2,-header3...]</term>
       <listitem>
          <para>
-            Add the header to a list of headers to remove completely; initially
-            the list is empty.
+           Remove all headers except listed.
          </para>
       </listitem>
    </varlistentry>
index 0cec65375c69778c9c03df42dc3345896b12a3d8..c36e40aa48d273acd39a081cd7f4ac93b6214068 100755 (executable)
@@ -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 header1[,h2,h3,...]:param1[,p2,p3,...]] [-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 header1[,h2,...]|*[,-h1,...]] [-R header:param] [--remove-params=header] [-beit mask] [-o output_file] [input_file [output_file]]
 """ % me)
     if errormsg:
         sys.stderr.write(errormsg + '\n')
@@ -111,8 +111,16 @@ def _decode_headers_params(msg, header, decode_all_params, param_list):
 def decode_headers(msg):
     "Decode message headers according to global options"
 
-    for header in gopts.remove_headers:
-        del msg[header]
+    for header_list in gopts.remove_headers:
+        header_list = header_list.split(',')
+        if header_list[0] == '*': # Remove all headers except listed
+            header_list = _get_exceptions(header_list)
+            for header in msg.keys():
+                if header.lower() not in header_list:
+                    del msg[header]
+        else: # Remove listed headers
+            for header in header_list:
+                del msg[header]
 
     for header in gopts.remove_all_params:
         value = msg[header]
diff --git a/test/expected/msg_16-1.txt b/test/expected/msg_16-1.txt
new file mode 100644 (file)
index 0000000..b2e4bb9
--- /dev/null
@@ -0,0 +1,81 @@
+From test Sat Feb  1 00:00:00 2014
+Return-Path: <>
+Delivered-To: scr-admin@socal-raves.org
+Date: Sun, 23 Sep 2001 20:14:35 -0700 (PDT)
+From: Internet Mail Delivery <postmaster@ucla.edu>
+Subject: Delivery Notification: Delivery has failed
+To: scr-admin@socal-raves.org
+Message-id: <0GK500B04D0B8X@cougar.noc.ucla.edu>
+MIME-version: 1.0
+Sender: scr-owner@socal-raves.org
+Errors-To: scr-owner@socal-raves.org
+X-BeenThere: scr@socal-raves.org
+X-Mailman-Version: 2.1a3
+Precedence: bulk
+Content-Type: multipart/report; boundary="Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)"
+
+
+--Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+X-MIME-Autoconverted: from iso-8859-1 to utf-8 by test id mimedecode.py
+
+This report relates to a message you sent with the following header fields:
+
+  Message-id: <002001c144a6$8752e060$56104586@oxy.edu>
+  Date: Sun, 23 Sep 2001 20:10:55 -0700
+  From: "Ian T. Henry" <henryi@oxy.edu>
+  To: SoCal Raves <scr@socal-raves.org>
+  Subject: [scr] yeah for Ians!!
+
+Your message cannot be delivered to the following recipients:
+
+  Recipient address: jangel1@cougar.noc.ucla.edu
+  Reason: recipient reached disk quota
+
+
+--Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)
+Content-type: message/DELIVERY-STATUS
+
+Original-envelope-id: 0GK500B4HD0888@cougar.noc.ucla.edu
+Reporting-MTA: dns; cougar.noc.ucla.edu
+
+Action: failed
+Status: 5.0.0 (recipient reached disk quota)
+Original-recipient: rfc822;jangel1@cougar.noc.ucla.edu
+Final-recipient: rfc822;jangel1@cougar.noc.ucla.edu
+
+
+--Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)
+Content-type: MESSAGE/RFC822
+
+Return-path: scr-admin@socal-raves.org
+Date: Sun, 23 Sep 2001 20:10:55 -0700
+From: "Ian T. Henry" <henryi@oxy.edu>
+Subject: [scr] yeah for Ians!!
+Sender: scr-admin@socal-raves.org
+To: SoCal Raves <scr@socal-raves.org>
+Errors-to: scr-admin@socal-raves.org
+Message-id: <002001c144a6$8752e060$56104586@oxy.edu>
+X-Mailer: Microsoft Outlook Express 5.50.4522.1200
+Precedence: bulk
+Delivered-to: scr-post@babylon.socal-raves.org
+Delivered-to: scr@socal-raves.org
+X-Converted-To-Plain-Text: from multipart/alternative by demime 0.98e
+X-Converted-To-Plain-Text: Alternative section used was text/plain
+X-BeenThere: scr@socal-raves.org
+X-Mailman-Version: 2.1a3
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+X-MIME-Autoconverted: from us-ascii to utf-8 by test id mimedecode.py
+
+I always love to find more Ian's that are over 3 years old!!
+
+Ian
+_______________________________________________
+For event info, list questions, or to unsubscribe, see http://www.socal-raves.org/
+
+
+
+--Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)--
+
diff --git a/test/expected/msg_16-2.txt b/test/expected/msg_16-2.txt
new file mode 100644 (file)
index 0000000..7daa4f5
--- /dev/null
@@ -0,0 +1,47 @@
+From test Sat Feb  1 00:00:00 2014
+MIME-version: 1.0
+Content-Type: multipart/report; boundary="Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)"
+
+
+--Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+X-MIME-Autoconverted: from iso-8859-1 to utf-8 by test id mimedecode.py
+
+This report relates to a message you sent with the following header fields:
+
+  Message-id: <002001c144a6$8752e060$56104586@oxy.edu>
+  Date: Sun, 23 Sep 2001 20:10:55 -0700
+  From: "Ian T. Henry" <henryi@oxy.edu>
+  To: SoCal Raves <scr@socal-raves.org>
+  Subject: [scr] yeah for Ians!!
+
+Your message cannot be delivered to the following recipients:
+
+  Recipient address: jangel1@cougar.noc.ucla.edu
+  Reason: recipient reached disk quota
+
+
+--Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)
+Content-type: message/DELIVERY-STATUS
+
+
+
+
+--Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)
+Content-type: MESSAGE/RFC822
+
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+X-MIME-Autoconverted: from us-ascii to utf-8 by test id mimedecode.py
+
+I always love to find more Ian's that are over 3 years old!!
+
+Ian
+_______________________________________________
+For event info, list questions, or to unsubscribe, see http://www.socal-raves.org/
+
+
+
+--Boundary_(ID_PGS2F2a+z+/jL7hupKgRhA)--
+
index 7f6c65c2dde8bdd6b99b8d057aa865ae2dc03cbf..ea33070656e873f33dcf43ee0b7bd614d782c571 100755 (executable)
@@ -51,6 +51,8 @@ test_file msg_22.txt msg_22.txt -P -p Content-Type,Content-Disposition:name,file
 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'
+test_file msg_16.txt msg_16-1.txt -r Received,List-Help,List-Post,List-Subscribe,List-Id,List-Unsubscribe,List-Archive
+test_file msg_16.txt msg_16-2.txt -r \*,-mime-version,-content-type
 
 if [ "$RC" -eq 0 ]; then
    echo "All tests passed!"