Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.1.X] Fixed #11144 -- When a to/from/cc header contains unicode, ma…

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

Backport of r11719 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11720 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit abd4344efe6bc9b138595a7d15998a0cbce5b9cf 1 parent 9a38c1c
Russell Keith-Magee freakboy3742 authored
Showing with 13 additions and 3 deletions.
  1. +2 −3 django/core/mail.py
  2. +11 −0 tests/regressiontests/mail/tests.py
5 django/core/mail.py
View
@@ -13,7 +13,7 @@
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.Header import Header
-from email.Utils import formatdate, parseaddr, formataddr
+from email.Utils import formatdate, getaddresses, formataddr
from django.conf import settings
from django.utils.encoding import smart_str, force_unicode
@@ -79,8 +79,7 @@ def forbid_multi_line_headers(name, val):
except UnicodeEncodeError:
if name.lower() in ('to', 'from', 'cc'):
result = []
- for item in val.split(', '):
- nm, addr = parseaddr(item)
+ for nm, addr in getaddresses((val,)):
nm = str(Header(nm, settings.DEFAULT_CHARSET))
result.append(formataddr((nm, str(addr))))
val = ', '.join(result)
11 tests/regressiontests/mail/tests.py
View
@@ -95,6 +95,17 @@
>>> message['From']
'from@example.com'
+# Regression for #11144 - When a to/from/cc header contains unicode,
+# make sure the email addresses are parsed correctly (especially
+# with regards to commas)
+>>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['"Firstname Sürname" <to@example.com>','other@example.com'])
+>>> email.message()['To']
+'=?utf-8?q?Firstname_S=C3=BCrname?= <to@example.com>, other@example.com'
+
+>>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['"Sürname, Firstname" <to@example.com>','other@example.com'])
+>>> email.message()['To']
+'=?utf-8?q?S=C3=BCrname=2C_Firstname?= <to@example.com>, other@example.com'
+
# Handle attachments within an multipart/alternative mail correctly (#9367)
# (test is not as precise/clear as it could be w.r.t. email tree structure,
# but it's good enough.)
Please sign in to comment.
Something went wrong with that request. Please try again.