Fixed #5778 -- Changed the way we detect if a string is non-ASCII when creating

email headers. This fixes a problem that was showing up on some (but not all)
systems.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6551 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-10-20 07:53:54 +00:00
parent f34935c37f
commit a0fdd7c7dd
1 changed files with 2 additions and 2 deletions

View File

@ -73,7 +73,7 @@ class SafeMIMEText(MIMEText):
if '\n' in val or '\r' in val:
raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name)
try:
val = str(force_unicode(val))
val = force_unicode(val).encode('ascii')
except UnicodeEncodeError:
if name.lower() in ('to', 'from', 'cc'):
result = []
@ -92,7 +92,7 @@ class SafeMIMEMultipart(MIMEMultipart):
if '\n' in val or '\r' in val:
raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name)
try:
val = str(force_unicode(val))
val = force_unicode(val).encode('ascii')
except UnicodeEncodeError:
if name.lower() in ('to', 'from', 'cc'):
result = []