From b3b242008b4eab47b662108836df911ef0095755 Mon Sep 17 00:00:00 2001 From: Michael Grinich Date: Sun, 2 Nov 2014 16:31:50 -0800 Subject: [PATCH 1/4] Fix for decoding errors if the list includes a non-ASCII string. --- flanker/addresslib/address.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flanker/addresslib/address.py b/flanker/addresslib/address.py index e158b644..88f173b6 100644 --- a/flanker/addresslib/address.py +++ b/flanker/addresslib/address.py @@ -130,7 +130,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(address_list) # parse try: From a63fe09ca60af9ef5f3a3bd2b3bbf85f95e7fc0a Mon Sep 17 00:00:00 2001 From: Christine Spang Date: Sat, 10 Jan 2015 11:28:08 -0800 Subject: [PATCH 2/4] Add regression test for non-ascii email address parsing. --- tests/addresslib/address_test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/addresslib/address_test.py b/tests/addresslib/address_test.py index e35aa16c..d301fcae 100644 --- a/tests/addresslib/address_test.py +++ b/tests/addresslib/address_test.py @@ -106,6 +106,14 @@ 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 ', 'Os Wi '] + lst = parse_list(al) + eq_(2, len(lst)) + eq_('=?utf-8?q?Aur=C3=A9lien_Berger?= ', lst[0].full_spec()) + eq_('Os Wi ', lst[1].full_spec()) + + def test_edge_cases(): email = EmailAddress('"foo.bar@"@example.com') eq_('"foo.bar@"@example.com', email.address) From ede112b6e42dbc3be3e0725db635bec1d9700a06 Mon Sep 17 00:00:00 2001 From: Christine Spang Date: Tue, 13 Jan 2015 13:45:59 -0800 Subject: [PATCH 3/4] Failing test case for case where parse_list() received Address object. --- tests/addresslib/address_test.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/addresslib/address_test.py b/tests/addresslib/address_test.py index d301fcae..13088a42 100644 --- a/tests/addresslib/address_test.py +++ b/tests/addresslib/address_test.py @@ -114,6 +114,16 @@ def test_addresslist_non_ascii_list_input(): eq_('Os Wi ', lst[1].full_spec()) +def test_addresslist_address_obj_list_input(): + al = [EmailAddress(u'Aurélien Berger '), + UrlAddress('https://www.example.com')] + lst = parse_list(al) + eq_(2, len(lst)) + eq_('=?utf-8?q?Aur=C3=A9lien_Berger?= ', + 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) From 1dea030ba20e3416c730a97c909134152ec73f79 Mon Sep 17 00:00:00 2001 From: Christine Spang Date: Tue, 13 Jan 2015 13:47:01 -0800 Subject: [PATCH 4/4] Fix parse_list() to handle Address objects with unicode properly also. --- flanker/addresslib/address.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/flanker/addresslib/address.py b/flanker/addresslib/address.py index 88f173b6..c27abef5 100644 --- a/flanker/addresslib/address.py +++ b/flanker/addresslib/address.py @@ -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): """ @@ -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(address_list) + address_list = ', '.join(_normalize_address_list(address_list)) # parse try: