Code

Ticket #1235: django-mail-charset-support.2.diff

File django-mail-charset-support.2.diff, 1.1 KB (added by akaihola, 8 years ago)

magic-removalized version of the patch, with Header() import

Line 
1Index: django/core/mail.py
2===================================================================
3--- django/core/mail.py (revision 2442)
4+++ django/core/mail.py (working copy)
5@@ -2,6 +2,7 @@
6 
7 from django.conf import settings
8 from email.MIMEText import MIMEText
9+from email.Header import Header
10 import smtplib
11 
12 class BadHeaderError(ValueError):
13@@ -12,6 +13,8 @@
14         "Forbids multi-line headers, to prevent header injection."
15         if '\n' in val or '\r' in val:
16             raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name)
17+        if name == 'Subject':
18+            val = Header(val, settings.DEFAULT_CHARSET)
19         MIMEText.__setitem__(self, name, val)
20 
21 def send_mail(subject, message, from_email, recipient_list, fail_silently=False):
22@@ -39,7 +42,7 @@
23         if not recipient_list:
24             continue
25         from_email = from_email or settings.DEFAULT_FROM_EMAIL
26-        msg = SafeMIMEText(message)
27+        msg = SafeMIMEText(message, 'plain', settings.DEFAULT_CHARSET)
28         msg['Subject'] = subject
29         msg['From'] = from_email
30         msg['To'] = ', '.join(recipient_list)