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 29f63a5..c46f31b 100644
a
|
b
|
Content
|
471 | 471 | >>> message.as_string() |
472 | 472 | 'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: Subject\nFrom: from@example.com\nTo: to@example.com\nCc: cc@example.com\nDate: ...\nMessage-ID: <...>\n\nContent' |
473 | 473 | |
| 474 | # Allow IDN in send_mail (14301) |
| 475 | |
| 476 | >>> from_email = u'from@öäü.com' |
| 477 | >>> to_email = u'to@öäü.com' |
| 478 | >>> connection = mail.get_connection('django.core.mail.backends.console.EmailBackend') |
| 479 | >>> send_mail('Subject', 'Content', from_email, [to_email], connection=connection) |
| 480 | Content-Type: text/plain; charset="utf-8" |
| 481 | MIME-Version: 1.0 |
| 482 | Content-Transfer-Encoding: quoted-printable |
| 483 | Subject: Subject |
| 484 | From: =?utf-8?b?ZnJvbUDDg8K2w4PCpMODwrwuY29t?= |
| 485 | To: =?utf-8?b?dG9Aw4PCtsODwqTDg8K8LmNvbQ==?= |
| 486 | Date: ... |
| 487 | Message-ID: ... |
| 488 | |
| 489 | Content |
| 490 | ------------------------------------------------------------------------------- |
| 491 | 1 |
| 492 | |
474 | 493 | """ |