Ticket #7574: 7574.patch

File 7574.patch, 919 bytes (added by Matthias Kestenholz, 16 years ago)
  • django/core/mail.py

    diff --git a/django/core/mail.py b/django/core/mail.py
    index b607573..9b59cfb 100644
    a b class BadHeaderError(ValueError):  
    7171
    7272def forbid_multi_line_headers(name, val):
    7373    """Forbids multi-line headers, to prevent header injection."""
    74     if '\n' in val or '\r' in val:
    75         raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name))
    7674    try:
    7775        val = force_unicode(val).encode('ascii')
    7876    except UnicodeEncodeError:
    def forbid_multi_line_headers(name, val):  
    8583            val = ', '.join(result)
    8684        else:
    8785            val = Header(force_unicode(val), settings.DEFAULT_CHARSET)
     86    if '\n' in val or '\r' in val:
     87        raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name))
    8888    return name, val
    8989
    9090class SafeMIMEText(MIMEText):
Back to Top