diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index cdff2ff..4ac44b5 100644
a
|
b
|
EMAIL_HOST = 'localhost'
|
165 | 165 | # Port for sending e-mail. |
166 | 166 | EMAIL_PORT = 25 |
167 | 167 | |
| 168 | # Default character set for email. Defaults to DEFAULT_CHARSET |
| 169 | EMAIL_CHARSET = None |
| 170 | |
168 | 171 | # Optional SMTP authentication information for EMAIL_HOST. |
169 | 172 | EMAIL_HOST_USER = '' |
170 | 173 | EMAIL_HOST_PASSWORD = '' |
diff --git a/django/core/mail/message.py b/django/core/mail/message.py
index 91a10a0..297b8e9 100644
a
|
b
|
def make_msgid(idstring=None):
|
56 | 56 | |
57 | 57 | def forbid_multi_line_headers(name, val, encoding): |
58 | 58 | """Forbids multi-line headers, to prevent header injection.""" |
59 | | encoding = encoding or settings.DEFAULT_CHARSET |
| 59 | encoding = encoding or settings.EMAIL_CHARSET or settings.DEFAULT_CHARSET |
60 | 60 | val = force_unicode(val) |
61 | 61 | if '\n' in val or '\r' in val: |
62 | 62 | raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name)) |
… |
… |
class EmailMessage(object):
|
138 | 138 | return self.connection |
139 | 139 | |
140 | 140 | def message(self): |
141 | | encoding = self.encoding or settings.DEFAULT_CHARSET |
| 141 | encoding = self.encoding or settings.EMAIL_CHARSET or settings.DEFAULT_CHARSET |
142 | 142 | msg = SafeMIMEText(smart_str(self.body, encoding), |
143 | 143 | self.content_subtype, encoding) |
144 | 144 | msg = self._create_message(msg) |
diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
index 84be585..6027434 100644
a
|
b
|
BadHeaderError: Header values can't contain newlines (got u'Subject\nInjection T
|
131 | 131 | >>> email.message()['Subject'].encode() |
132 | 132 | u'=?iso-8859-1?q?Message_from_Firstname_S=FCrname?=' |
133 | 133 | |
| 134 | # Regression for #XXXXX - Make sure the EMAIL_CHARSET is used. |
| 135 | >>> old_email_charset = settings.EMAIL_CHARSET |
| 136 | >>> settings.EMAIL_CHARSET = 'iso-2022-jp' |
| 137 | >>> email = EmailMessage('件名', '本文', 'bounce@example.com', ['"仲居良介" <to@example.com>'], headers={'From': '"池田洋介" <from@example.com>'}) |
| 138 | >>> message = email.message() |
| 139 | >>> message['From'] |
| 140 | '=?iso-2022-jp?b?GyRCQ1NFRE1OMnAbKEI=?= <from@example.com>' |
| 141 | >>> message['To'] |
| 142 | '=?iso-2022-jp?b?GyRCQ2c1b05JMnAbKEI=?= <to@example.com>' |
| 143 | >>> message["Subject"].encode() |
| 144 | u'=?iso-2022-jp?b?GyRCN29MPhsoQg==?=' |
| 145 | >>> settings.EMAIL_CHARSET = old_email_charset |
| 146 | |
134 | 147 | # Make sure headers can be set with a different encoding than utf-8 in SafeMIMEMultipart as well |
135 | 148 | >>> headers = {"Date": "Fri, 09 Nov 2001 01:08:47 -0000", "Message-ID": "foo"} |
136 | 149 | >>> subject, from_email, to = 'hello', 'from@example.com', '"Sürname, Firstname" <to@example.com>' |