From 7a7ab08316b4aa4f7b18b50626cb0dc16dde3efb Mon Sep 17 00:00:00 2001 From: Folker Bernitt Date: Tue, 10 Mar 2015 16:45:05 +0100 Subject: added support for 7 and 8bit content transfer encoding. - Issue #312 --- service/pixelated/adapter/model/mail.py | 4 +++- service/test/unit/adapter/test_mail.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py index c5c9e424..8521babf 100644 --- a/service/pixelated/adapter/model/mail.py +++ b/service/pixelated/adapter/model/mail.py @@ -234,7 +234,9 @@ class PixelatedMail(Mail): decoding_map = { 'quoted-printable': lambda content, content_type: unicode(content.decode('quopri'), content_type), - 'base64': lambda content, content_type: content.decode('base64').decode('utf-8') + 'base64': lambda content, content_type: content.decode('base64').decode('utf-8'), + '7bit': lambda content, content_type: content.encode(content_type), + '8bit': lambda content, content_type: content.encode(content_type) } if encoding: return decoding_map[encoding](part['content'], content_type) diff --git a/service/test/unit/adapter/test_mail.py b/service/test/unit/adapter/test_mail.py index ed7b945a..7bbf4cd4 100644 --- a/service/test/unit/adapter/test_mail.py +++ b/service/test/unit/adapter/test_mail.py @@ -211,6 +211,28 @@ class TestPixelatedMail(unittest.TestCase): self.assertEquals(body, mail.text_plain_body) + def test_that_body_understands_7bit(self): + body = u'testtext' + encoded_body = body + + fdoc, hdoc, bdoc = test_helper.leap_mail() + parts = {'alternatives': []} + parts['alternatives'].append({'content': encoded_body, 'headers': {'Content-Transfer-Encoding': '7bit'}}) + mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier, parts=parts) + + self.assertEquals(body, mail.text_plain_body) + + def test_that_body_understands_8bit(self): + body = u'testtext' + encoded_body = body + + fdoc, hdoc, bdoc = test_helper.leap_mail() + parts = {'alternatives': []} + parts['alternatives'].append({'content': encoded_body, 'headers': {'Content-Transfer-Encoding': '8bit'}}) + mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier, parts=parts) + + self.assertEquals(body, mail.text_plain_body) + def test_bounced_mails_are_recognized(self): bounced_mail_hdoc = os.path.join(os.path.dirname(__file__), '..', 'fixtures', 'bounced_mail_hdoc.json') with open(bounced_mail_hdoc) as f: -- cgit v1.2.3