Author: jezdez Date: 2010-12-21 09:26:49 -0600 (Tue, 21 Dec 2010) New Revision: 15006
Modified: django/trunk/django/core/mail/backends/smtp.py django/trunk/tests/regressiontests/mail/tests.py Log: Fixed #14301 -- Further refine changes made in r14216 to support non-ASCII characters in email addresses. Thanks, Claude Peroz and Andi Albrecht. Modified: django/trunk/django/core/mail/backends/smtp.py =================================================================== --- django/trunk/django/core/mail/backends/smtp.py 2010-12-21 15:19:19 UTC (rev 15005) +++ django/trunk/django/core/mail/backends/smtp.py 2010-12-21 15:26:49 UTC (rev 15006) @@ -91,13 +91,19 @@ self._lock.release() return num_sent + def _sanitize(self, email): + name, domain = email.split('@', 1) + email = '@'.join([name, domain.encode('idna')]) + return email + def _send(self, email_message): """A helper method that does the actual sending.""" if not email_message.recipients(): return False + from_email = self._sanitize(email_message.from_email) + recipients = map(self._sanitize, email_message.recipients()) try: - self.connection.sendmail(email_message.from_email, - email_message.recipients(), + self.connection.sendmail(from_email, recipients, email_message.message().as_string()) except: if not self.fail_silently: Modified: django/trunk/tests/regressiontests/mail/tests.py =================================================================== --- django/trunk/tests/regressiontests/mail/tests.py 2010-12-21 15:19:19 UTC (rev 15005) +++ django/trunk/tests/regressiontests/mail/tests.py 2010-12-21 15:26:49 UTC (rev 15006) @@ -408,3 +408,25 @@ self.assertEqual(message.from_email, from_email) self.assertEqual(message.to, [to_email]) self.assertTrue(message.message().as_string().startswith('Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: Subject\nFrom: =?utf-8?b?ZnLDtm1Aw7bDpMO8LmNvbQ==?=\nTo: =?utf-8?b?dMO2QMO2w6TDvC5jb20=?=')) + + def test_idn_smtp_send(self): + import smtplib + smtplib.SMTP = MockSMTP + from_email = u'fr...@öäü.com' + to_email = u't...@öäü.com' + connection = mail.get_connection('django.core.mail.backends.smtp.EmailBackend') + self.assertTrue(send_mail('Subject', 'Content', from_email, [to_email], connection=connection)) + +class MockSMTP(object): + def __init__(self, host='', port=0, local_hostname=None, + timeout=1): + pass + + def sendmail(self, from_addr, to_addrs, msg, mail_options=[], + rcpt_options=[]): + for addr in to_addrs: + str(addr.split('@', 1)[-1]) + return {} + + def quit(self): + return 0 -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.