From: Menno Smits Date: Mon, 23 Nov 2015 22:49:28 +0000 (+1300) Subject: Normalise to unicode in Address.__str__ X-Git-Tag: 1.0.0~1^2~7 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=a2b3fdc21da297cefad33d373916dc53ba6b1d7c;p=imapclient.git Normalise to unicode in Address.__str__ __str__ was failing when the address fields were bytes (which the typically are). Fixes #186. --- diff --git a/imapclient/response_types.py b/imapclient/response_types.py index 8038db2..166c20c 100644 --- a/imapclient/response_types.py +++ b/imapclient/response_types.py @@ -2,11 +2,15 @@ # Released subject to the New BSD License # Please see http://en.wikipedia.org/wiki/BSD_licenses +from __future__ import unicode_literals + from collections import namedtuple from email.utils import formataddr import six +from .util import to_unicode + class Envelope(namedtuple("Envelope", "date subject from_ sender reply_to to " + "cc bcc in_reply_to message_id")): @@ -50,7 +54,9 @@ class Address(namedtuple("Address", "name route mailbox host")): """ def __str__(self): - return formataddr((self.name, self.mailbox + '@' + self.host)) + return formataddr(( + to_unicode(self.name), + to_unicode(self.mailbox) + '@' + to_unicode(self.host))) class SearchIds(list): diff --git a/imapclient/test/test_response_parser.py b/imapclient/test/test_response_parser.py index 2b13486..3c13534 100644 --- a/imapclient/test/test_response_parser.py +++ b/imapclient/test/test_response_parser.py @@ -484,6 +484,14 @@ class TestParseFetchResponse(unittest.TestCase): } }) + def test_Address_str(self): + self.assertEqual(str(Address(b"Mary Jane", None, b"mary", b"jane.org")), + "Mary Jane ") + + self.assertEqual(str(Address("Mary Jane", None, "mary", "jane.org")), + "Mary Jane ") + + def add_crlf(text): return CRLF.join(text.splitlines()) + CRLF