diff --git a/django/core/mail/message.py b/django/core/mail/message.py
index a0cb09f..2311102 100644
a
|
b
|
def forbid_multi_line_headers(name, val, encoding):
|
67 | 67 | result = [] |
68 | 68 | for nm, addr in getaddresses((val,)): |
69 | 69 | nm = str(Header(nm.encode(encoding), encoding)) |
70 | | result.append(formataddr((nm, str(addr)))) |
| 70 | try: |
| 71 | addr = addr.encode('ascii') |
| 72 | except UnicodeEncodeError: # IDN |
| 73 | addr = str(Header(addr.encode(encoding), encoding)) |
| 74 | result.append(formataddr((nm, addr))) |
71 | 75 | val = ', '.join(result) |
72 | 76 | else: |
73 | 77 | val = Header(val.encode(encoding), encoding) |
diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
index d2f7562..586f0b2 100644
a
|
b
|
class MailTests(TestCase):
|
363 | 363 | |
364 | 364 | settings.ADMINS = old_admins |
365 | 365 | settings.MANAGERS = old_managers |
| 366 | |
| 367 | def test_idn(self): |
| 368 | """Test internationalized email adresses""" |
| 369 | # Regression for #14301. |
| 370 | mail.outbox = [] |
| 371 | from_email = u'fröm@öäü.com' |
| 372 | to_email = u'tö@öäü.com' |
| 373 | connection = mail.get_connection('django.core.mail.backends.locmem.EmailBackend') |
| 374 | send_mail('Subject', 'Content', from_email, [to_email], connection=connection) |
| 375 | |
| 376 | self.assertEqual(len(mail.outbox), 1) |
| 377 | message = mail.outbox[0] |
| 378 | self.assertEqual(message.subject, 'Subject') |
| 379 | self.assertEqual(message.from_email, u'fröm@öäü.com') |
| 380 | self.assertEqual(message.to, [to_email]) |