diff --git a/imbox/parser.py b/imbox/parser.py index 1cab82f..d13c139 100644 --- a/imbox/parser.py +++ b/imbox/parser.py @@ -154,7 +154,7 @@ def parse_email(raw_email, policy=None): content = decode_content(part) is_inline = content_disposition is None \ - or content_disposition == "inline" + or content_disposition.startswith("inline") if content_type == "text/plain" and is_inline: body['plain'].append(content) elif content_type == "text/html" and is_inline: diff --git a/tests/parser_tests.py b/tests/parser_tests.py index 6069a14..0ac1b70 100644 --- a/tests/parser_tests.py +++ b/tests/parser_tests.py @@ -124,6 +124,62 @@ cvED9AIR3TCAAAMAqh+p+YMVeBQAAAAASUVORK5CYII= """ +raw_email_encoded_another_bad_multipart = b"""Delivered-To: receiver@example.com +Return-Path: +Mime-Version: 1.0 +Date: Wed, 22 Mar 2017 15:21:55 -0500 +Message-ID: <58D29693.192A.0075.1@wimort.com> +Subject: Re: Reaching Out About Peoples Home Equity +From: sender@example.com +To: receiver@example.com +Content-Type: multipart/alternative; boundary="____NOIBTUQXSYRVOOAFLCHY____" + + +--____NOIBTUQXSYRVOOAFLCHY____ +Content-Type: text/plain; charset=iso-8859-15 +Content-Transfer-Encoding: quoted-printable +Content-Disposition: inline; + modification-date="Wed, 22 Mar 2017 15:21:55 -0500" + +Chloe, + +--____NOIBTUQXSYRVOOAFLCHY____ +Content-Type: multipart/related; boundary="____XTSWHCFJMONXSVGPVDLY____" + + +--____XTSWHCFJMONXSVGPVDLY____ +Content-Type: text/html; charset=iso-8859-15 +Content-Transfer-Encoding: quoted-printable +Content-Disposition: inline; + modification-date="Wed, 22 Mar 2017 15:21:55 -0500" + + + +
Chloe,
+ +--____XTSWHCFJMONXSVGPVDLY____ +Content-ID: +Content-Type: image/gif +Content-Transfer-Encoding: base64 + +R0lGODlhHgHCAPf/AIOPr9GvT7SFcZZjVTEuMLS1tZKUlJN0Znp4eEA7PV1aWvz8+8V6Zl1BNYxX +HvOZ1/zmOd95agUEADs= +--____XTSWHCFJMONXSVGPVDLY____ +Content-ID: +Content-Type: image/xxx +Content-Transfer-Encoding: base64 + +R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw== +--____XTSWHCFJMONXSVGPVDLY____-- + +--____NOIBTUQXSYRVOOAFLCHY____-- +""" + + class TestParser(unittest.TestCase): def test_parse_email(self): @@ -144,6 +200,12 @@ class TestParser(unittest.TestCase): parsed_email = parse_email(open(os.path.join(TEST_DIR, '8422.msg'), 'rb').read()) self.assertEqual("Following up Re: Looking to connect, let's schedule a call!", parsed_email.subject) + def test_parse_email_inline_body(self): + parsed_email = parse_email(raw_email_encoded_another_bad_multipart) + self.assertEqual("Re: Reaching Out About Peoples Home Equity", parsed_email.subject) + self.assertTrue(parsed_email.body['plain']) + self.assertTrue(parsed_email.body['html']) + def test_parse_email_bad_multipart(self): parsed_email = parse_email(raw_email_encoded_bad_multipart) self.assertEqual("Re: Looking to connect with you...", parsed_email.subject)