Django

Code

Changeset 1810

Show
Ignore:
Timestamp:
12/30/05 22:11:01 (3 years ago)
Author:
adrian
Message:

magic-removal: Merged to [1809]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/django/conf/project_template/settings.py

    r1678 r1810  
    6161TEMPLATE_DIRS = ( 
    6262    # Put strings here, like "/home/html/django_templates". 
     63    # Always use forward slashes, even on Windows. 
    6364) 
    6465 
  • django/branches/magic-removal/django/core/mail.py

    r1796 r1810  
    55import smtplib 
    66 
     7class BadHeaderError(ValueError): 
     8    pass 
     9 
    710class SafeMIMEText(MIMEText): 
    811    def __setitem__(self, name, val): 
    912        "Forbids multi-line headers, to prevent header injection." 
    1013        if '\n' in val or '\r' in val: 
    11             raise ValueError, "Header values can't contain newlines (got %r for header %r)" % (val, name) 
     14            raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name) 
    1215        MIMEText.__setitem__(self, name, val) 
    1316 
  • django/branches/magic-removal/docs/email.txt

    r1796 r1810  
    128128by forbidding newlines in header values. If any ``subject``, ``from_email`` or 
    129129``recipient_list`` contains a newline, the e-mail function (e.g. 
    130 ``send_mail()``) will raise ``ValueError`` and, hence, will not send the 
    131 e-mail. It's your responsibility to validate all data before passing it to the 
    132 e-mail functions. 
     130``send_mail()``) will raise ``django.core.mail.BadHeaderError`` (a subclass of 
     131``ValueError``) and, hence, will not send the e-mail. It's your responsibility 
     132to validate all data before passing it to the e-mail functions. 
    133133 
    134134Here's an example view that takes a ``subject``, ``message`` and ``from_email`` 
     
    136136"/contact/thanks/" when it's done:: 
    137137 
    138     from django.core.mail import send_mail 
     138    from django.core.mail import send_mail, BadHeaderError 
    139139 
    140140    def send_email(request): 
     
    142142        message = request.POST.get('message', '') 
    143143        from_email = request.POST.get('from_email', '') 
    144         if subject and message and from_email \ 
    145                 and '\n' not in subject and '\n' not in message 
    146                 and '\n' not in from_email: 
    147             send_mail(subject, message, from_email, ['admin@example.com']) 
     144        if subject and message and from_email: 
     145            try: 
     146                send_mail(subject, message, from_email, ['admin@example.com']) 
     147            except BadHeaderError: 
     148                return HttpResponse('Invalid header found.') 
    148149            return HttpResponseRedirect('/contact/thanks/') 
    149150        else: 
  • django/branches/magic-removal/docs/settings.txt

    r1775 r1810  
    585585Default: ``()`` (Empty tuple) 
    586586 
    587 List of locations of the template source files, in search order. See the 
    588 `template documentation`_. 
     587List of locations of the template source files, in search order. Note that 
     588these paths should use Unix-style forward slashes, even on Windows. 
     589 
     590See the `template documentation`_. 
    589591 
    590592TEMPLATE_FILE_EXTENSION 
  • django/branches/magic-removal/docs/templates_python.txt

    r1775 r1810  
    389389    ) 
    390390 
     391Note that these paths should use Unix-style forward slashes, even on Windows. 
     392 
    391393The Python API 
    392394~~~~~~~~~~~~~~