Ticket #14301: bug14301.diff

File bug14301.diff, 1.9 KB (added by Andi Albrecht, 14 years ago)
  • django/core/mail/message.py

    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):  
    6767            result = []
    6868            for nm, addr in getaddresses((val,)):
    6969                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)))
    7175            val = ', '.join(result)
    7276        else:
    7377            val = Header(val.encode(encoding), encoding)
  • tests/regressiontests/mail/tests.py

    diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
    index 29f63a5..c46f31b 100644
    a b Content  
    471471>>> message.as_string()
    472472'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'
    473473
     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)
     480Content-Type: text/plain; charset="utf-8"
     481MIME-Version: 1.0
     482Content-Transfer-Encoding: quoted-printable
     483Subject: Subject
     484From: =?utf-8?b?ZnJvbUDDg8K2w4PCpMODwrwuY29t?=
     485To: =?utf-8?b?dG9Aw4PCtsODwqTDg8K8LmNvbQ==?=
     486Date: ...
     487Message-ID: ...
     488
     489Content
     490-------------------------------------------------------------------------------
     4911
     492
    474493"""
Back to Top