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 #790 #792

Merged
merged 3 commits into from
Apr 30, 2019
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
8 changes: 7 additions & 1 deletion sendgrid/helpers/mail/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
__html_parser__ = HTMLParser()
html_entity_decode = __html_parser__.unescape

try:
basestring = basestring
except NameError:
# Define basestring when Python >= 3.0
basestring = str


class Email(object):
"""An email address with an optional name."""
Expand Down Expand Up @@ -82,7 +88,7 @@ def name(self, value):
:param value: Name associated with this email.
:type value: string
"""
if not (value is None or isinstance(value, str)):
if not (value is None or isinstance(value, basestring)):
raise TypeError('name must be of type string.')

# Escape common CSV delimiters as workaround for
Expand Down
20 changes: 20 additions & 0 deletions test/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,26 @@ def test_add_name(self):

self.assertEqual(email.name, name)

def test_add_unicode_name(self):
name = u"SomeName"
email = Email(name=name)

self.assertEqual(email.name, name)

def test_add_name_email(self):
name = "SomeName"
address = "[email protected]"
email = Email(email=address, name=name)
self.assertEqual(email.name, name)
self.assertEqual(email.email, "[email protected]")

def test_add_unicode_name_email(self):
name = u"SomeName"
address = u"[email protected]"
email = Email(email=address, name=name)
self.assertEqual(email.name, name)
self.assertEqual(email.email, u"[email protected]")

def test_add_rfc_function_finds_name_not_email(self):
name = "SomeName"
email = Email(name)
Expand Down Expand Up @@ -60,3 +73,10 @@ def test_add_name_with_comma(self):
email.name = name

self.assertEqual(email.name, '"' + name + '"')

def test_add_unicode_name_with_comma(self):
email = Email()
name = u"Name, Some"
email.name = name

self.assertEqual(email.name, u'"' + name + u'"')