diff --git a/product/ERP5/Document/EmailDocument.py b/product/ERP5/Document/EmailDocument.py index 29fec853c262cd5ba0dfb601015040828dfc34c7..7f89178696ac7883ef28afa0dd96f4daddae43d3 100644 --- a/product/ERP5/Document/EmailDocument.py +++ b/product/ERP5/Document/EmailDocument.py @@ -125,9 +125,11 @@ class EmailDocument(File, TextDocument): for (name, value) in self._getMessage().items(): for text, encoding in decode_header(value): if encoding is not None: - result[name] = result.get(name, '') + text.decode(encoding).encode('utf-8') + text = text.decode(encoding).encode('utf-8') + if name in result: + result[name] = '%s %s' % (result[name], text) else: - result[name] = result.get(name, '') + text + result[name] = text return result security.declareProtected(Permissions.AccessContentsInformation, 'getAttachmentInformationList') diff --git a/product/ERP5/tests/testCRM.py b/product/ERP5/tests/testCRM.py index 314e21efdd955eed8b43fec583cf83b838a38b7f..cb61dc89663271017559b5c4a1a7f024df54644a 100644 --- a/product/ERP5/tests/testCRM.py +++ b/product/ERP5/tests/testCRM.py @@ -485,16 +485,27 @@ class TestCRMMailIngestion(ERP5TypeTestCase): self.assertEqual(document.getSourceValue().getTitle(), 'Sender') self.assertEqual(document.getDestinationValue().getTitle(), 'Me') + def test_encoding(self): + document = self._ingestMail(filename='encoded') + + get_transaction().commit() + self.tic() + + self.assertEqual(document.getContentInformation().get('To'), + 'Me <me@erp5.org>') + self.assertEqual(document.getSourceValue().getTitle(), 'Sender') + self.assertEqual(document.getDestinationValue().getTitle(), 'Me') + self.assertEqual(document.getContentInformation().get('Subject'), + 'Test 茅nc枚d猫d email') + self.assertEqual(document.getTitle(), 'Test 茅nc枚d猫d email') + self.assertEqual(document.getTextContent(), 'c枚nt茅nt\n') + ## TODO: ## ## def test_attachements(self): ## event = self._ingestMail('with_attachements') ## -## def test_encoding(self): -## event = self._ingestMail('utf8') -## - class TestCRMMailSend(ERP5TypeTestCase): """Test Mail Sending for CRM diff --git a/product/ERP5/tests/test_data/crm_emails/encoded b/product/ERP5/tests/test_data/crm_emails/encoded new file mode 100644 index 0000000000000000000000000000000000000000..bbd93ca8184fafbdc762f1e2b9b6be2bef727e1f --- /dev/null +++ b/product/ERP5/tests/test_data/crm_emails/encoded @@ -0,0 +1,10 @@ +Date: Mon, 7 Jul 2008 10:17:56 +0200 +From: Sender <sender@customer.com> +To: Me <me@erp5.org> +Subject: Test =?utf8?B?w6luY8O2ZMOoZA==?= email +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf8 +Content-Disposition: inline +Content-Transfer-Encoding: quoted-printable + +c=C3=B6nt=C3=A9nt