Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 1b1379a182a055a696152fcc0620f9ec4c590c6d 1 parent 3a89212
@malcolmt malcolmt authored
Showing with 10 additions and 9 deletions.
  1. +10 −9 django/core/mail.py
View
19 django/core/mail.py
@@ -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):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.