Ticket #14301: 14301.2.diff

File 14301.2.diff, 1.7 KB (added by Jannis Leidel, 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 d2f7562..586f0b2 100644
    a b class MailTests(TestCase):  
    363363
    364364        settings.ADMINS = old_admins
    365365        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])
Back to Top