diff --git a/django/core/mail.py b/django/core/mail.py index e9d8a150a1..2f252df724 100644 --- a/django/core/mail.py +++ b/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): """