summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-03-12 17:02:50 +0100
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-03-12 17:03:45 +0100
commite2f3f7a6922d8ca0365e93e03ab170d1ab1d575e (patch)
treea38c57ec004e9f8ec6deafc1da5e0705447f0fbd
parent8022339834dabf5d2817157b25a2b65997989474 (diff)
Fixed problem with multi line content type header field.
- Bugfix - Issues #313, #322
-rw-r--r--service/pixelated/adapter/model/mail.py2
-rw-r--r--service/test/unit/adapter/test_mail.py11
2 files changed, 12 insertions, 1 deletions
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index 8521babf..c11b2aa3 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -82,7 +82,7 @@ class Mail(object):
def _parse_charset_header(self, charset_header, default_charset='utf-8'):
try:
- return re.compile('.*charset=([a-zA-Z0-9-]+)').match(charset_header).group(1)
+ return re.compile('.*charset=([a-zA-Z0-9-]+)', re.MULTILINE | re.DOTALL).match(charset_header).group(1)
except:
return default_charset
diff --git a/service/test/unit/adapter/test_mail.py b/service/test/unit/adapter/test_mail.py
index 7bbf4cd4..317db5de 100644
--- a/service/test/unit/adapter/test_mail.py
+++ b/service/test/unit/adapter/test_mail.py
@@ -184,6 +184,17 @@ class TestPixelatedMail(unittest.TestCase):
self.assertEquals(u'H\xe4llo', mail.text_plain_body)
self.assertEquals(u'<p>H\xe4llo</p>', mail.html_body)
+ def test_multi_line_content_type_header_is_supported(self):
+ plain_headers = {'Content-Type': 'text/plain;\ncharset=iso-8859-1', 'Content-Transfer-Encoding': 'quoted-printable'}
+ html_headers = {'Content-Type': 'text/html;\ncharset=utf-8', 'Content-Transfer-Encoding': 'quoted-printable'}
+ parts = {'alternatives': [{'content': 'H=E4llo', 'headers': plain_headers}, {'content': '<p>H=C3=A4llo</p>', 'headers': html_headers}]}
+
+ mail = PixelatedMail.from_soledad(None, None, self._create_bdoc(raw='some raw body'), parts=parts, soledad_querier=None)
+
+ self.assertEqual(2, len(mail.alternatives))
+ self.assertEquals(u'H\xe4llo', mail.text_plain_body)
+ self.assertEquals(u'<p>H\xe4llo</p>', mail.html_body)
+
def test_clean_line_breaks_on_address_headers(self):
many_recipients = 'One <one@mail.com>,\nTwo <two@mail.com>, Normal <normal@mail.com>,\nalone@mail.com'
headers = {'Cc': many_recipients,