Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #14, skip empty headers #15

Merged
merged 2 commits into from
Mar 21, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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)
----------------

Expand Down
4 changes: 0 additions & 4 deletions pyramid_mailer/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ def validate(self):
if not (self.recipients or self.cc or self.bcc):
raise InvalidMessage("No recipients have been added")

if (self.cc or self.bcc) and not self.recipients:
raise InvalidMessage("Must have at least one direct recipient "
"even if cc or bcc set")

if not self.body and not self.html:
raise InvalidMessage("No body has been set")

Expand Down
2 changes: 2 additions & 0 deletions pyramid_mailer/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 27 additions & 4 deletions pyramid_mailer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,22 @@ def test_cc_without_recipients(self):
body="testing",
cc=["tosomeoneelse@example.com"])
mailer = Mailer()
from pyramid_mailer.exceptions import InvalidMessage
self.assertRaises(InvalidMessage, mailer.send, msg)
msgid = mailer.send(msg)
response = msg.get_response()

self.assertTrue("Cc: tosomeoneelse@example.com" in str(response))
self.assertTrue(msgid)

def test_cc_without_recipients_2(self):

from pyramid_mailer.message import Message

msg = Message(subject="testing",
sender="sender@example.com",
body="testing",
cc=["tosomeoneelse@example.com"])
response = msg.get_response()
self.assertTrue("Cc: tosomeoneelse@example.com" in str(response))

def test_bcc_without_recipients(self):

Expand All @@ -181,8 +195,11 @@ def test_bcc_without_recipients(self):
body="testing",
bcc=["tosomeoneelse@example.com"])
mailer = Mailer()
from pyramid_mailer.exceptions import InvalidMessage
self.assertRaises(InvalidMessage, mailer.send, msg)
msgid = mailer.send(msg)
response = msg.get_response()

self.assertFalse("Bcc: tosomeoneelse@example.com" in str(response))
self.assertTrue(msgid)

def test_attach(self):

Expand Down Expand Up @@ -959,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
Expand Down