Skip to content

Commit

Permalink
Merge branch 'hotfix/0.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
fedelemantuano committed Sep 16, 2016
2 parents 95f5331 + 576898d commit feb14e7
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
5 changes: 3 additions & 2 deletions mailparser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ def _parse(self):
"{}".format("--" + self._message.get_boundary()),
"{}".format("--" + self._message.get_boundary() + "--"),
)
p = email.message_from_string(epilogue)
parts.append(p)
if epilogue:
p = email.message_from_string(epilogue)
parts.append(p)

# walk all mail parts
for p in parts:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from setuptools import setup


VERSION = (0, 2, 1)
VERSION = (0, 2, 2)
__version__ = VERSION
__versionstr__ = '.'.join(map(str, VERSION))

Expand Down
File renamed without changes.
61 changes: 61 additions & 0 deletions tests/mails/mail_malformed_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Return-Path: <>
Delivered-To: [email protected]
Received: (qmail 32129 invoked from network); 22 Aug 2016 09:22:13 -0000
Received: from c.netpar.com.br (HELO apus.netpar.com.br) (189.125.104.100)
by smtp.customers.net with SMTP; 22 Aug 2016 09:22:13 -0000
To: [email protected]
Subject: Delivery failure ([email protected])
From: [email protected]
Message-Id: <[email protected]>
Date: Mon, 22 Aug 2016 06:23:36 -0300
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status; boundary="48461/50/1471857816/MailSite/apus.netpar.com.br"

--48461/50/1471857816/MailSite/apus.netpar.com.br
Content-Type: text/plain

Your message has encountered delivery problems
to the following recipient(s):

abh
(Was addressed to [email protected])
Delivery failed
User's mailbox quota exceeded




--48461/50/1471857816/MailSite/apus.netpar.com.br
Content-Type: message/delivery-status
Content-Disposition: attachment; filename="DSN57BAC498.txt"

Reporting-MTA: dns; apus.netpar.com.br
Arrival-Date: Mon, 22 Aug 2016 06:23:36 -0300

Final-Recipient: rfc822; [email protected]
Action: failed
Status: 4.2.2 (Persistent transient failure - mailbox: mailbox full)

--48461/50/1471857816/MailSite/apus.netpar.com.br
Content-Type: message/rfc822-headers

Received: from cygnus.netpar.com.br (unverified [189.125.104.24]) by apus.netpar.com.br
(Rockliffe SMTPRA 4.5.6) with ESMTP id <[email protected]> for <[email protected]>;
Mon, 22 Aug 2016 06:23:36 -0300
Received: from [117.201.229.175] (unknown [117.201.229.175])
by cygnus.netpar.com.br (Postfix) with ESMTP id 9B8AE886048E
for <[email protected]>; Mon, 22 Aug 2016 09:22:04 +0000 (UTC)
From: "Reynaldo Stevens" <[email protected]>
To: <[email protected]>
Subject: Trabajo perfecto a distancia
Date: 22 Aug 2016 18:37:49 +0400
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0045_01D1FC84.01C36A99"
X-Mailer: Microsoft Outlook 14.0
Thread-Index: Ac1doyjrxh5tdsxl1doyjrxh5tdsxl==
Content-Language: en

--48461/50/1471857816/MailSite/apus.netpar.com.br--

19 changes: 17 additions & 2 deletions tests/test_mail_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
mail_test_1 = os.path.join(base_path, 'mails', 'mail_test_1')
mail_test_2 = os.path.join(base_path, 'mails', 'mail_test_2')
mail_test_3 = os.path.join(base_path, 'mails', 'mail_test_3')
mail_malformed = os.path.join(base_path, 'mails', 'mail_malformed')
mail_malformed_1 = os.path.join(base_path, 'mails', 'mail_malformed_1')
mail_malformed_2 = os.path.join(base_path, 'mails', 'mail_malformed_2')

sys.path.append(root)
import mailparser
Expand Down Expand Up @@ -133,7 +134,7 @@ def test_types(self):

def test_defects_anomalies(self):
parser = mailparser.MailParser()
parser.parse_from_file(mail_malformed)
parser.parse_from_file(mail_malformed_1)

self.assertEqual(True, parser.has_defects)
self.assertEqual(1, len(parser.defects))
Expand All @@ -151,6 +152,20 @@ def test_defects_anomalies(self):
self.assertEqual(2, len(parser.anomalies))
self.assertIn("anomalies", parser.parsed_mail_obj)

def test_defects_bug(self):
parser = mailparser.MailParser()
parser.parse_from_file(mail_malformed_2)

self.assertEqual(True, parser.has_defects)
self.assertEqual(1, len(parser.defects))
self.assertEqual(1, len(parser.defects_category))
self.assertIn("defects", parser.parsed_mail_obj)
self.assertIn("StartBoundaryNotFoundDefect", parser.defects_category)
self.assertIsInstance(parser.parsed_mail_json, unicode)

result = len(parser.attachments_list)
self.assertEqual(0, result)

def test_add_content_type(self):
parser = mailparser.MailParser()
parser.parse_from_file(mail_test_3)
Expand Down

0 comments on commit feb14e7

Please sign in to comment.