From 3f7c5fd9a9506957b722a47f2fbdb7e587654823 Mon Sep 17 00:00:00 2001 From: Patrick Maia and Victor Shyba Date: Mon, 27 Oct 2014 14:40:55 -0300 Subject: Card #30 - fixes bug in which % character on multipart body was causing an exception --- service/pixelated/adapter/mail.py | 8 ++++---- service/test/unit/adapter/mail_test.py | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'service') diff --git a/service/pixelated/adapter/mail.py b/service/pixelated/adapter/mail.py index f152c73f..82b4d0a6 100644 --- a/service/pixelated/adapter/mail.py +++ b/service/pixelated/adapter/mail.py @@ -197,14 +197,14 @@ class PixelatedMail(Mail): if self.parts and len(self.parts['alternatives']) > 1: body = '' for alternative in self.parts['alternatives']: - body += "--%(boundary)s\n" + body += '--' + self.boundary + '\n' for header, value in alternative['headers'].items(): - body += "%s: %s\n" % (header, value) + body += '%s: %s\n' % (header, value) body += '\n' body += alternative['content'] body += '\n' - body += '--%(boundary)s--' - return body % {'boundary': self.boundary} + body += '--' + self.boundary + '--' + return body else: return self.bdoc.content['raw'] diff --git a/service/test/unit/adapter/mail_test.py b/service/test/unit/adapter/mail_test.py index 35fe411e..8b35b181 100644 --- a/service/test/unit/adapter/mail_test.py +++ b/service/test/unit/adapter/mail_test.py @@ -102,6 +102,15 @@ class TestPixelatedMail(unittest.TestCase): self.assertRegexpMatches(mail.body, '\nContent-Type: text/plain\n\nblablabla\n') self.assertRegexpMatches(mail.body, '.*--' + mail.boundary + '--$') + def test_percent_character_is_allowed_on_body(self): + parts = {'alternatives': [], 'attachments': []} + parts['alternatives'].append({'content': '100% happy with percentage symbol', 'headers': {'Content-Type': 'text/plain'}}) + parts['alternatives'].append({'content': '

100% happy with percentage symbol

', 'headers': {'Content-Type': 'text/html'}}) + + mail = PixelatedMail.from_soledad(None, None, None, None, parts=parts) + + self.assertRegexpMatches(mail.body, '([\s\S]*100%){2}') + class InputMailTest(unittest.TestCase): mail_dict = lambda x: { -- cgit v1.2.3