From 9b68db3414c847b241e4e8ce2a0a636521d10c5c Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 10 Mar 2014 21:26:16 +0400 Subject: [PATCH] Fix a minor bug If a multipart message (or a subpart) lacks any textual content - avoid putting an excessive newline. --- ANNOUNCE | 3 +++ mimedecode.py | 9 ++++++++- test/expected/msg_02-1.txt | 2 -- test/expected/msg_02.txt | 2 -- test/expected/msg_07.txt | Bin 4179 -> 4178 bytes test/expected/msg_08.txt | 1 - test/expected/msg_09.txt | 1 - test/expected/msg_10.txt | 1 - test/expected/msg_12.txt | 2 -- test/expected/msg_12a.txt | 2 -- test/expected/msg_13-1.txt | 1 - test/expected/msg_13.txt | Bin 4404 -> 4403 bytes test/expected/msg_22-1.txt | Bin 1902 -> 1901 bytes test/expected/msg_22.txt | Bin 2016 -> 2015 bytes test/expected/msg_23.txt | 1 - test/expected/msg_24.txt | 1 - test/expected/msg_28.txt | 1 - test/expected/msg_30.txt | 1 - test/expected/msg_34.txt | 1 - test/expected/msg_36.txt | 2 -- test/expected/msg_37.txt | 1 - test/expected/msg_38.txt | 3 --- test/expected/msg_39.txt | 2 -- 23 files changed, 11 insertions(+), 26 deletions(-) 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 78f67ea078726b1fd469722070ede4f0b3f87aaf..9cfaa68d524a38bb740cc5398d8f440567cd3881 100644 GIT binary patch delta 11 Scmcbta7keS<7P(2AbtQFT?3r} delta 10 Rcmcbla9Lpi{^p~+0Siay3Yy#N=yeD 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> -- 2.39.5