Code

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

File django-mail-charset-support.diff, 1.2 KB (added by igor@…, 8 years ago)

patch for support different charsets in mail messages

Line 
1Index: django/core/mail.py
2===================================================================
3--- django/core/mail.py (revision 1986)
4+++ django/core/mail.py (working copy)
5@@ -1,6 +1,7 @@
6 # Use this module for e-mailing.
7 
8 from django.conf.settings import DEFAULT_FROM_EMAIL, EMAIL_HOST, EMAIL_SUBJECT_PREFIX
9+from django.conf.settings import DEFAULT_CHARSET
10 from email.MIMEText import MIMEText
11 import smtplib
12 
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, 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 DEFAULT_FROM_EMAIL
26-        msg = SafeMIMEText(message)
27+        msg = SafeMIMEText(message, 'plain', DEFAULT_CHARSET)
28         msg['Subject'] = subject
29         msg['From'] = from_email
30         msg['To'] = ', '.join(recipient_list)