From: Oleg Broytman Date: Mon, 10 Mar 2014 17:26:16 +0000 (+0400) Subject: Fix a minor bug X-Git-Tag: v2.5.0~30 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=9b68db3414c847b241e4e8ce2a0a636521d10c5c;p=mimedecode.git Fix a minor bug If a multipart message (or a subpart) lacks any textual content - avoid putting an excessive newline. --- diff --git a/ANNOUNCE b/ANNOUNCE index 58e552e..613982d 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -33,6 +33,9 @@ level). Add option -B to skip content-transfer-decoding binary attachments. + Fix a minor bug: if a multipart message (or a subpart) lacks any textual +content - avoid putting an excessive newline. + WHAT'S NEW in version 2.4.0 (2014-03-08) Change option -d to accept a comma-separated list of headers: diff --git a/mimedecode.py b/mimedecode.py index c12afbb..8971efa 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -325,12 +325,19 @@ def decode_multipart(msg): if msg.preamble: # Preserve the first part, it is probably not a RFC822-message output(msg.preamble) # Usually it is just a few lines of text (MIME warning) + if msg.preamble is not None: + output("\n") + first_subpart = True boundary = msg.get_boundary() for subpart in msg.get_payload(): if boundary: - output("\n--%s\n" % boundary) + if first_subpart: + first_subpart = False + else: + output("\n") + output("--%s\n" % boundary) # Recursively decode all parts of the subpart decode_message(subpart) diff --git a/test/expected/msg_02-1.txt b/test/expected/msg_02-1.txt index 410e9f3..f854c3e 100644 --- a/test/expected/msg_02-1.txt +++ b/test/expected/msg_02-1.txt @@ -9,7 +9,6 @@ X-Mailman-Version: 2.0.4 Content-Type: multipart/mixed; boundary="192.168.1.2.889.32614.987812255.500.21814" X-Mailer: Mailman v2.0.4; test="set" - --192.168.1.2.889.32614.987812255.500.21814 Content-description: Masthead (Ppp digest, Vol 1 #2) MIME-Version: 1.0 @@ -48,7 +47,6 @@ Today's Topics: --192.168.1.2.889.32614.987812255.500.21814 Content-Type: multipart/digest; boundary="__--__--" - --__--__-- Message: 1 diff --git a/test/expected/msg_02.txt b/test/expected/msg_02.txt index fa2fcee..f12dd12 100644 --- a/test/expected/msg_02.txt +++ b/test/expected/msg_02.txt @@ -9,7 +9,6 @@ X-Mailer: Mailman v2.0.4 X-Mailman-Version: 2.0.4 Content-Type: multipart/mixed; boundary="192.168.1.2.889.32614.987812255.500.21814" - --192.168.1.2.889.32614.987812255.500.21814 Content-description: Masthead (Ppp digest, Vol 1 #2) MIME-Version: 1.0 @@ -48,7 +47,6 @@ Today's Topics: --192.168.1.2.889.32614.987812255.500.21814 Content-Type: multipart/digest; boundary="__--__--" - --__--__-- Message: 1 diff --git a/test/expected/msg_07.txt b/test/expected/msg_07.txt index 78f67ea..9cfaa68 100644 Binary files a/test/expected/msg_07.txt and b/test/expected/msg_07.txt differ diff --git a/test/expected/msg_08.txt b/test/expected/msg_08.txt index 47e4e0c..fd966be 100644 --- a/test/expected/msg_08.txt +++ b/test/expected/msg_08.txt @@ -6,7 +6,6 @@ Subject: Lyrics Date: Fri, 20 Apr 2001 19:35:02 -0400 Content-Type: multipart/mixed; boundary="BOUNDARY" - --BOUNDARY MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" diff --git a/test/expected/msg_09.txt b/test/expected/msg_09.txt index 5057f17..8c8d773 100644 --- a/test/expected/msg_09.txt +++ b/test/expected/msg_09.txt @@ -6,7 +6,6 @@ Subject: Lyrics Date: Fri, 20 Apr 2001 19:35:02 -0400 Content-Type: multipart/mixed; boundary="BOUNDARY" - --BOUNDARY MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" diff --git a/test/expected/msg_10.txt b/test/expected/msg_10.txt index 34da890..e59a81b 100644 --- a/test/expected/msg_10.txt +++ b/test/expected/msg_10.txt @@ -6,7 +6,6 @@ Subject: Lyrics Date: Fri, 20 Apr 2001 19:35:02 -0400 Content-Type: multipart/mixed; boundary="BOUNDARY" - --BOUNDARY Content-Transfer-Encoding: 7bit MIME-Version: 1.0 diff --git a/test/expected/msg_12.txt b/test/expected/msg_12.txt index 36229a0..e765d01 100644 --- a/test/expected/msg_12.txt +++ b/test/expected/msg_12.txt @@ -6,7 +6,6 @@ Subject: Lyrics Date: Fri, 20 Apr 2001 19:35:02 -0400 Content-Type: multipart/mixed; boundary="BOUNDARY" - --BOUNDARY MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" @@ -24,7 +23,6 @@ X-MIME-Autoconverted: from iso-8859-1 to utf-8 by test id mimedecode.py --BOUNDARY Content-Type: multipart/mixed; boundary="ANOTHER" - --ANOTHER MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" diff --git a/test/expected/msg_12a.txt b/test/expected/msg_12a.txt index 1ab7b36..9d67283 100644 --- a/test/expected/msg_12a.txt +++ b/test/expected/msg_12a.txt @@ -6,7 +6,6 @@ Subject: Lyrics Date: Fri, 20 Apr 2001 19:35:02 -0400 Content-Type: multipart/mixed; boundary="BOUNDARY" - --BOUNDARY MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" @@ -24,7 +23,6 @@ X-MIME-Autoconverted: from iso-8859-1 to utf-8 by test id mimedecode.py --BOUNDARY Content-Type: multipart/mixed; boundary="ANOTHER" - --ANOTHER MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" diff --git a/test/expected/msg_13-1.txt b/test/expected/msg_13-1.txt index e5728bb..5c5ef07 100644 --- a/test/expected/msg_13-1.txt +++ b/test/expected/msg_13-1.txt @@ -6,7 +6,6 @@ Subject: Here is your dingus fish Date: Fri, 20 Apr 2001 19:35:02 -0400 Content-Type: multipart/mixed; boundary="OUTER" - --OUTER Content-Type: text/plain; charset="us-ascii" diff --git a/test/expected/msg_13.txt b/test/expected/msg_13.txt index a7abbec..1e0cdf3 100644 Binary files a/test/expected/msg_13.txt and b/test/expected/msg_13.txt differ diff --git a/test/expected/msg_22-1.txt b/test/expected/msg_22-1.txt index 0d58be1..1545c73 100644 Binary files a/test/expected/msg_22-1.txt and b/test/expected/msg_22-1.txt differ diff --git a/test/expected/msg_22.txt b/test/expected/msg_22.txt index a7b5b35..0caea80 100644 Binary files a/test/expected/msg_22.txt and b/test/expected/msg_22.txt differ diff --git a/test/expected/msg_23.txt b/test/expected/msg_23.txt index ae2e638..ff9dfa8 100644 --- a/test/expected/msg_23.txt +++ b/test/expected/msg_23.txt @@ -2,7 +2,6 @@ From test Sat Feb 1 00:00:00 2014 From: aperson@dom.ain Content-Type: multipart/mixed; boundary="BOUNDARY" - --BOUNDARY Content-Type: text/plain diff --git a/test/expected/msg_24.txt b/test/expected/msg_24.txt index eb27f14..05c2552 100644 --- a/test/expected/msg_24.txt +++ b/test/expected/msg_24.txt @@ -5,7 +5,6 @@ Subject: A subject To: aperson@dom.ain From: bperson@dom.ain - --BOUNDARY diff --git a/test/expected/msg_28.txt b/test/expected/msg_28.txt index bf3272b..3c6ae18 100644 --- a/test/expected/msg_28.txt +++ b/test/expected/msg_28.txt @@ -3,7 +3,6 @@ From: aperson@dom.ain MIME-Version: 1.0 Content-Type: multipart/digest; boundary=BOUNDARY - --BOUNDARY Content-Type: message/rfc822 diff --git a/test/expected/msg_30.txt b/test/expected/msg_30.txt index deae715..d75a444 100644 --- a/test/expected/msg_30.txt +++ b/test/expected/msg_30.txt @@ -3,7 +3,6 @@ From: aperson@dom.ain MIME-Version: 1.0 Content-Type: multipart/digest; boundary=BOUNDARY - --BOUNDARY To: aa@bb.org diff --git a/test/expected/msg_34.txt b/test/expected/msg_34.txt index f8826ad..110f9f5 100644 --- a/test/expected/msg_34.txt +++ b/test/expected/msg_34.txt @@ -3,7 +3,6 @@ From: aperson@dom.ain To: bperson@dom.ain Content-Type: multipart/digest; boundary=XYZ - --XYZ Content-Type: text/plain diff --git a/test/expected/msg_36.txt b/test/expected/msg_36.txt index 7ee1898..48a9d36 100644 --- a/test/expected/msg_36.txt +++ b/test/expected/msg_36.txt @@ -6,7 +6,6 @@ From: Internet-Drafts@ietf.org Subject: I-D ACTION:draft-ietf-mboned-mix-00.txt Date: Tue, 22 Dec 1998 16:55:06 -0500 - --NextPart Blah blah blah @@ -14,7 +13,6 @@ Blah blah blah --NextPart Content-Type: Multipart/Alternative; Boundary="OtherAccess" - --OtherAccess Content-Type: Message/External-body; access-type="mail-server"; diff --git a/test/expected/msg_37.txt b/test/expected/msg_37.txt index 0739fdb..fc94500 100644 --- a/test/expected/msg_37.txt +++ b/test/expected/msg_37.txt @@ -1,7 +1,6 @@ From test Sat Feb 1 00:00:00 2014 Content-Type: multipart/mixed; boundary=ABCDE - --ABCDE Content-Type: text/x-one diff --git a/test/expected/msg_38.txt b/test/expected/msg_38.txt index 3c580c7..a56a754 100644 --- a/test/expected/msg_38.txt +++ b/test/expected/msg_38.txt @@ -2,17 +2,14 @@ From test Sat Feb 1 00:00:00 2014 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" - ------- =_aaaaaaaaaa0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa1" Content-ID: <20592.1022586929.1@example.com> - ------- =_aaaaaaaaaa1 Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa2" Content-ID: <20592.1022586929.2@example.com> - ------- =_aaaaaaaaaa2 Content-Type: text/plain Content-ID: <20592.1022586929.3@example.com> diff --git a/test/expected/msg_39.txt b/test/expected/msg_39.txt index 26b1689..9c99abd 100644 --- a/test/expected/msg_39.txt +++ b/test/expected/msg_39.txt @@ -2,12 +2,10 @@ From test Sat Feb 1 00:00:00 2014 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" - ------- =_aaaaaaaaaa0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa1" Content-ID: <20592.1022586929.1@example.com> - ------- =_aaaaaaaaaa1 Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa1" Content-ID: <20592.1022586929.2@example.com>