Skip to content

Commit

Permalink
Merge pull request #67 from inboxapp/master
Browse files Browse the repository at this point in the history
Fix for decoding errors if the list includes a non-ASCII string.
  • Loading branch information
russjones committed Jan 14, 2015
2 parents 73602f8 + 1dea030 commit 42cd727
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
15 changes: 14 additions & 1 deletion flanker/addresslib/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@
from flanker.mime.message.headers.encodedword import mime_to_unicode
from urlparse import urlparse


def _normalize_address_list(address_list):
parts = []

for addr in address_list:
if isinstance(addr, Address):
parts.append(unicode(addr))
if isinstance(addr, basestring):
parts.append(addr)

return parts


@metrics_wrapper()
def parse(address, addr_spec_only=False, metrics=False):
"""
Expand Down Expand Up @@ -130,7 +143,7 @@ def parse_list(address_list, strict=False, as_tuple=False, metrics=False):

# if we have a list, transform it into a string first
if isinstance(address_list, list):
address_list = ', '.join([str(addr) for addr in address_list])
address_list = ', '.join(_normalize_address_list(address_list))

# parse
try:
Expand Down
18 changes: 18 additions & 0 deletions tests/addresslib/address_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ def test_addresslist_with_apostrophe():
eq_(u'Eugueny ώ Kontsevoy', lst[0].display_name)


def test_addresslist_non_ascii_list_input():
al = [u'Aurélien Berger <[email protected]>', 'Os Wi <[email protected]>']
lst = parse_list(al)
eq_(2, len(lst))
eq_('=?utf-8?q?Aur=C3=A9lien_Berger?= <[email protected]>', lst[0].full_spec())
eq_('Os Wi <[email protected]>', lst[1].full_spec())


def test_addresslist_address_obj_list_input():
al = [EmailAddress(u'Aurélien Berger <[email protected]>'),
UrlAddress('https://www.example.com')]
lst = parse_list(al)
eq_(2, len(lst))
eq_('=?utf-8?q?Aur=C3=A9lien_Berger?= <[email protected]>',
lst[0].full_spec())
eq_('https://www.example.com', lst[1].full_spec())


def test_edge_cases():
email = EmailAddress('"foo.bar@"@example.com')
eq_('"foo.bar@"@example.com', email.address)
Expand Down

0 comments on commit 42cd727

Please sign in to comment.