1
0
mirror of https://github.com/django/django.git synced 2024-12-25 02:26:12 +00:00

[py3] Workarounded a Python bug in mail header encoding

This commit is contained in:
Claude Paroz 2012-08-17 20:16:38 +02:00
parent 6086f7356d
commit 6e4c984098

View File

@ -99,7 +99,12 @@ def sanitize_address(addr, encoding):
if isinstance(addr, six.string_types):
addr = parseaddr(force_text(addr))
nm, addr = addr
nm = Header(nm, encoding).encode()
# This try-except clause is needed on Python 3 < 3.2.4
# http://bugs.python.org/issue14291
try:
nm = Header(nm, encoding).encode()
except UnicodeEncodeError:
nm = Header(nm, 'utf-8').encode()
try:
addr.encode('ascii')
except UnicodeEncodeError: # IDN