Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11144 -- When a to/from/cc header contains unicode, make sure …

…the email addresses are parsed correctly (especially with regards to commas). Thanks to rmt for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11719 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit dd5d7622a5d8f95c304267b1bcb0d9a8d28d6d8e 1 parent b59aa81
Russell Keith-Magee authored November 04, 2009
5  django/core/mail/message.py
@@ -7,7 +7,7 @@
7 7
 from email.MIMEMultipart import MIMEMultipart
8 8
 from email.MIMEBase import MIMEBase
9 9
 from email.Header import Header
10  
-from email.Utils import formatdate, parseaddr, formataddr
  10
+from email.Utils import formatdate, getaddresses, formataddr
11 11
 
12 12
 from django.conf import settings
13 13
 from django.core.mail.utils import DNS_NAME
@@ -64,8 +64,7 @@ def forbid_multi_line_headers(name, val):
64 64
     except UnicodeEncodeError:
65 65
         if name.lower() in ('to', 'from', 'cc'):
66 66
             result = []
67  
-            for item in val.split(', '):
68  
-                nm, addr = parseaddr(item)
  67
+            for nm, addr in getaddresses((val,)):
69 68
                 nm = str(Header(nm, settings.DEFAULT_CHARSET))
70 69
                 result.append(formataddr((nm, str(addr))))
71 70
             val = ', '.join(result)
11  tests/regressiontests/mail/tests.py
@@ -101,6 +101,17 @@
101 101
 >>> message['From']
102 102
 'from@example.com'
103 103
 
  104
+# Regression for #11144 - When a to/from/cc header contains unicode,
  105
+# make sure the email addresses are parsed correctly (especially
  106
+# with regards to commas)
  107
+>>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['"Firstname Sürname" <to@example.com>','other@example.com'])
  108
+>>> email.message()['To']
  109
+'=?utf-8?q?Firstname_S=C3=BCrname?= <to@example.com>, other@example.com'
  110
+
  111
+>>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['"Sürname, Firstname" <to@example.com>','other@example.com'])
  112
+>>> email.message()['To']
  113
+'=?utf-8?q?S=C3=BCrname=2C_Firstname?= <to@example.com>, other@example.com'
  114
+
104 115
 # Handle attachments within an multipart/alternative mail correctly (#9367)
105 116
 # (test is not as precise/clear as it could be w.r.t. email tree structure,
106 117
 #  but it's good enough.)

0 notes on commit dd5d762

Please sign in to comment.
Something went wrong with that request. Please try again.