mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Backported the fix from [5581] (unicode-branch) to trunk. Fixes a method
resolution order problem when setting email headers. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5582 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3a892122f2
commit
1b1379a182
@ -62,22 +62,23 @@ def make_msgid(idstring=None):
|
||||
class BadHeaderError(ValueError):
|
||||
pass
|
||||
|
||||
class SafeHeaderMixin(object):
|
||||
class SafeMIMEText(MIMEText):
|
||||
def __setitem__(self, name, val):
|
||||
"Forbids multi-line headers, to prevent header injection."
|
||||
if '\n' in val or '\r' in val:
|
||||
raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name)
|
||||
if name == "Subject":
|
||||
val = Header(val, settings.DEFAULT_CHARSET)
|
||||
# Note: using super() here is safe; any __setitem__ overrides must use
|
||||
# the same argument signature.
|
||||
super(SafeHeaderMixin, self).__setitem__(name, val)
|
||||
MIMEText.__setitem__(self, name, val)
|
||||
|
||||
class SafeMIMEText(MIMEText, SafeHeaderMixin):
|
||||
pass
|
||||
|
||||
class SafeMIMEMultipart(MIMEMultipart, SafeHeaderMixin):
|
||||
pass
|
||||
class SafeMIMEMultipart(MIMEMultipart):
|
||||
def __setitem__(self, name, val):
|
||||
"Forbids multi-line headers, to prevent header injection."
|
||||
if '\n' in val or '\r' in val:
|
||||
raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name)
|
||||
if name == "Subject":
|
||||
val = Header(val, settings.DEFAULT_CHARSET)
|
||||
MIMEMultipart.__setitem__(self, name, val)
|
||||
|
||||
class SMTPConnection(object):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user