From 5db89f501d4ed922bf7ad2be5a5ddab1f7506dd7 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 18 Feb 2014 22:28:50 +0400 Subject: [PATCH] Change type guessing The message or part is an RFC-822 message if it has at least one header, not necessary Content-Type. --- mimedecode.py | 2 +- test/expected/msg_35.txt | 1 + test/expected/msg_43.txt | 100 ++++++++++----------------------------- 3 files changed, 27 insertions(+), 76 deletions(-) diff --git a/mimedecode.py b/mimedecode.py index 0be095b..7604fb2 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -263,7 +263,7 @@ def decode_message(msg): if msg.is_multipart(): decode_multipart(msg) - elif msg.has_key("Content-Type"): # Simple one-part message - decode it + elif len(msg): # Simple one-part message (there are headers) - decode it decode_part(msg) else: # Not a message, just text - copy it literally output(msg.as_string()) diff --git a/test/expected/msg_35.txt b/test/expected/msg_35.txt index 4b1b824..65b8703 100644 --- a/test/expected/msg_35.txt +++ b/test/expected/msg_35.txt @@ -1,3 +1,4 @@ +From test Sat Feb 1 00:00:00 2014 From: aperson@dom.ain To: bperson@dom.ain Subject: here's something interesting diff --git a/test/expected/msg_43.txt b/test/expected/msg_43.txt index 8386fd4..33aaca1 100644 --- a/test/expected/msg_43.txt +++ b/test/expected/msg_43.txt @@ -45,201 +45,151 @@ 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