From 68a893237c9cdf67f91909981e024d7bf306b73c Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Fri, 9 Jan 2015 13:11:33 -0200 Subject: #164 sometimes a mail with more than one alternative will not have an html part --- service/pixelated/adapter/model/mail.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'service/pixelated/adapter/model/mail.py') 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): -- cgit v1.2.3