Fix UnicecodeDecodeError parsing email
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
||||
import unittest
|
||||
from imbox.parser import *
|
||||
|
||||
import os
|
||||
import sys
|
||||
if sys.version_info.major < 3 or sys.version_info.minor < 3:
|
||||
SMTP = False
|
||||
@@ -10,6 +11,9 @@ else:
|
||||
from email.policy import SMTP
|
||||
|
||||
|
||||
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
raw_email = """Delivered-To: johndoe@gmail.com
|
||||
X-Originating-Email: [martin@amon.cx]
|
||||
Message-ID: <test0@example.com>
|
||||
@@ -98,6 +102,10 @@ class TestParser(unittest.TestCase):
|
||||
self.assertEqual('Выписка по карте', parsed_email.subject)
|
||||
self.assertEqual('Выписка по карте 1234', parsed_email.body['html'][0])
|
||||
|
||||
def test_parse_email_invalid_unicode(self):
|
||||
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_ignores_header_casing(self):
|
||||
self.assertEqual('one', parse_email('Message-ID: one').message_id)
|
||||
self.assertEqual('one', parse_email('Message-Id: one').message_id)
|
||||
|
||||
Reference in New Issue
Block a user