From: Oleg Broytman Date: Sat, 8 Mar 2014 16:26:10 +0000 (+0400) Subject: Change option -r to accept a list of headers; * is allowed X-Git-Tag: v2.4.0~6 X-Git-Url: https://git.phdru.name/?p=mimedecode.git;a=commitdiff_plain;h=db0cd67905f741dcf93af7706c282afadf051718 Change option -r to accept a list of headers; * is allowed 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,... --- diff --git a/ANNOUNCE b/ANNOUNCE index d13c330..923a772 100644 --- 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 863f92c..a46034a 100644 --- 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: diff --git a/mimedecode.docbook b/mimedecode.docbook index 0346b2b..75ec367 100644 --- a/mimedecode.docbook +++ b/mimedecode.docbook @@ -62,7 +62,10 @@ - + + + + @@ -297,11 +300,20 @@ - -r header + -r header1[,header2,header3...] + + + Add the header(s) to a list of headers to remove completely; + initially the list is empty. + + + + + + -r *[,-header1,-header2,-header3...] - Add the header to a list of headers to remove completely; initially - the list is empty. + Remove all headers except listed. diff --git a/mimedecode.py b/mimedecode.py index 0cec653..c36e40a 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[,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 index 0000000..b2e4bb9 --- /dev/null +++ b/test/expected/msg_16-1.txt @@ -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 +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" + To: SoCal Raves + 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" +Subject: [scr] yeah for Ians!! +Sender: scr-admin@socal-raves.org +To: SoCal Raves +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 index 0000000..7daa4f5 --- /dev/null +++ b/test/expected/msg_16-2.txt @@ -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" + To: SoCal Raves + 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)-- + diff --git a/test/test_all b/test/test_all index 7f6c65c..ea33070 100755 --- a/test/test_all +++ b/test/test_all @@ -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!"