summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuda Dornelles <dudassdornelles@gmail.com>2015-01-09 13:11:33 -0200
committerPixpoa pairing <pixpoapairing@pixelated-project.org>2015-01-09 13:18:34 -0200
commit68a893237c9cdf67f91909981e024d7bf306b73c (patch)
tree1ee43c3204e07cf05a5222c3de4680e0068c8ba5
parent69a0650615935e7fd6a20656c4248b95cbe10317 (diff)
#164 sometimes a mail with more than one alternative will not have an html part
-rwxr-xr-xservice/go2
-rw-r--r--service/pixelated/adapter/model/mail.py5
-rw-r--r--service/test/unit/adapter/mail_test.py10
3 files changed, 14 insertions, 3 deletions
diff --git a/service/go b/service/go
index 241cae46..111f7515 100755
--- a/service/go
+++ b/service/go
@@ -24,7 +24,7 @@ function runPep8 {
pep8 pixelated test --ignore=E501
}
-if [ "$2" == 'test' ]; then
+if [ "$1" == 'test' ]; then
runPep8
runUnitTests
runIntegrationTests
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index 98533a74..7984cb05 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -236,8 +236,9 @@ class PixelatedMail(Mail):
@property
def html_body(self):
if self.parts and len(self.alternatives) > 1:
- html_part = [e for e in self.alternatives if re.match('text/html', e['headers']['Content-Type'])][0]
- return self._decode_part(html_part)
+ html_parts = [e for e in self.alternatives if re.match('text/html', e['headers'].get('Content-Type', ''))]
+ if len(html_parts):
+ return self._decode_part(html_parts[0])
@property
def headers(self):
diff --git a/service/test/unit/adapter/mail_test.py b/service/test/unit/adapter/mail_test.py
index a845d665..9dc54e66 100644
--- a/service/test/unit/adapter/mail_test.py
+++ b/service/test/unit/adapter/mail_test.py
@@ -151,6 +151,16 @@ class TestPixelatedMail(unittest.TestCase):
self.assertRegexpMatches(mail.html_body, '^<p>blablabla</p>$')
self.assertRegexpMatches(mail.text_plain_body, '^blablabla$')
+ def test_html_is_none_if_multiple_alternatives_have_no_html_part(self):
+ parts = {
+ 'attachments': [],
+ 'alternatives': [
+ {'content': u'content', 'headers': {u'Content-Type': u'text/plain; charset=us-ascii'}},
+ {'content': u'', 'headers': {u'Some info': u'info'}}]}
+
+ mail = PixelatedMail.from_soledad(None, None, None, parts=parts, soledad_querier=None)
+ self.assertIsNone(mail.html_body)
+
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'}})