From 70c8a3a1d7f08e10767f181a72314e9257022745 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 12 Feb 2014 04:17:15 +0400 Subject: [PATCH] Split decode_message into decode_multipart --- mimedecode.py | 16 ++++--- test/expected/msg_43.txt | 100 +++++++++++++++++++++++++++++---------- 2 files changed, 84 insertions(+), 32 deletions(-) diff --git a/mimedecode.py b/mimedecode.py index 9db4278..d3d23ff 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -231,8 +231,8 @@ def decode_part(msg): totext(msg, outstring) -def decode_message(msg): - "Decode message" +def decode_multipart(msg): + "Decode multipart" if msg.is_multipart(): decode_headers(msg) @@ -247,10 +247,8 @@ def decode_message(msg): if boundary: output("\n--%s\n" % boundary) - if subpart.is_multipart(): # Recursively decode all parts of the subpart - decode_message(subpart) - else: - decode_part(subpart) + # Recursively decode all parts of the subpart + decode_message(subpart) if boundary: output("\n--%s--\n" % boundary) @@ -258,9 +256,13 @@ def decode_message(msg): if msg.epilogue: output(msg.epilogue) +def decode_message(msg): + "Decode message" + + if msg.is_multipart(): + decode_multipart(msg) elif msg.has_key("Content-Type"): # Simple one-part message - decode it decode_part(msg) - else: # Not a message, just text - copy it literally output(msg.as_string()) diff --git a/test/expected/msg_43.txt b/test/expected/msg_43.txt index 33aaca1..8386fd4 100644 --- a/test/expected/msg_43.txt +++ b/test/expected/msg_43.txt @@ -45,151 +45,201 @@ Arrival-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) Final-Recipient: rfc822; xxxxxxx@dot.ca.gov Action: failed Status: 5.7.1 -Diagnostic-Code: smtp; 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: auto__mail.python.bat +Diagnostic-Code: smtp; + 550 5.7.1 Message content rejected, id=01956-02-2 - BANNED: + auto__mail.python.bat Last-Attempt-Date: Fri, 26 Nov 2004 19:41:44 -0800 (PST) -- 2.39.5