From 23e334b43047448be63db959ad896738c0e074d3 Mon Sep 17 00:00:00 2001 From: Ross Patterson Date: Tue, 20 Mar 2012 13:40:26 -0700 Subject: [PATCH] Workaround a Python 3.2.0 bug in handling emails with empty headers. Fixes #14. --- CHANGES.txt | 6 ++++++ pyramid_mailer/response.py | 2 ++ pyramid_mailer/tests.py | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index be69ac9..ae1d9a4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,9 @@ +0.7 (Unreleased) +---------------- + +- Workaround a Python 3.2.0 bug in handling emails with empty + headers. + 0.6 (2012-03-20) ---------------- diff --git a/pyramid_mailer/response.py b/pyramid_mailer/response.py index c29b9d9..234de24 100644 --- a/pyramid_mailer/response.py +++ b/pyramid_mailer/response.py @@ -343,6 +343,8 @@ def to_message(mail): if k.lower() in encoding.ADDR_HEADERS: if is_nonstr_iter(value): # not a string value = ", ".join(value) + if value == '': + continue out[k] = value out.extract_payload(mail) diff --git a/pyramid_mailer/tests.py b/pyramid_mailer/tests.py index 2c56241..650a14a 100644 --- a/pyramid_mailer/tests.py +++ b/pyramid_mailer/tests.py @@ -976,6 +976,12 @@ def test_no_ctype_no_parts(self): result = self._callFUT(mail) self.assertEqual(result.__class__, MIMEPart) + def test_empty_header(self): + mail = self._makeBase() + mail['To'] = '' + result = self._callFUT(mail) + self.assertFalse('To' in result) + class TestMIMEPart(unittest.TestCase): def _makeOne(self, type, **params): from pyramid_mailer.response import MIMEPart