diff --git a/kallithea/lib/rcmail/response.py b/kallithea/lib/rcmail/response.py --- a/kallithea/lib/rcmail/response.py +++ b/kallithea/lib/rcmail/response.py @@ -346,13 +346,13 @@ def to_message(mail, separator="; "): for k in mail.keys(): if k in ADDRESS_HEADERS_WHITELIST: - out[k.encode('ascii')] = header_to_mime_encoding( + out[k] = header_to_mime_encoding( mail[k], not_email=False, separator=separator ) else: - out[k.encode('ascii')] = header_to_mime_encoding( + out[k] = header_to_mime_encoding( mail[k], not_email=True ) @@ -443,12 +443,12 @@ def properly_encode_header(value, encode check different, then change this. """ try: - return value.encode("ascii") - except UnicodeEncodeError: + value.encode("ascii") + return value + except UnicodeError: if not not_email and VALUE_IS_EMAIL_ADDRESS(value): # this could have an email address, make sure we don't screw it up name, address = parseaddr(value) - return '"%s" <%s>' % ( - encoder.header_encode(name.encode("utf-8")), address) + return '"%s" <%s>' % (encoder.header_encode(name), address) - return encoder.header_encode(value.encode("utf-8")) + return encoder.header_encode(value) diff --git a/kallithea/tests/other/test_mail.py b/kallithea/tests/other/test_mail.py --- a/kallithea/tests/other/test_mail.py +++ b/kallithea/tests/other/test_mail.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + import mock import kallithea @@ -144,9 +146,9 @@ class TestMail(base.TestController): def test_send_mail_with_author_full_mail_from(self): mailserver = 'smtp.mailserver.org' - recipients = ['rcpt1', 'rcpt2'] + recipients = ['ræcpt1', 'receptor2 ', 'tæst@example.com', 'Tæst '] envelope_addr = 'noreply@mailserver.org' - envelope_from = 'Some Name <%s>' % envelope_addr + envelope_from = 'Söme Næme <%s>' % envelope_addr subject = 'subject' body = 'body' html_body = 'html_body'