From 1b1379a182a055a696152fcc0620f9ec4c590c6d Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sun, 1 Jul 2007 06:32:34 +0000 Subject: [PATCH] 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 --- django/core/mail.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) 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): """