Changeset 1810
- Timestamp:
- 12/30/05 22:11:01 (3 years ago)
- Files:
-
- django/branches/magic-removal/django/conf/locale/nl (copied) (copied from django/trunk/django/conf/locale/nl)
- django/branches/magic-removal/django/conf/locale/nl/LC_MESSAGES (copied) (copied from django/trunk/django/conf/locale/nl/LC_MESSAGES)
- django/branches/magic-removal/django/conf/locale/nl/LC_MESSAGES/django.mo (copied) (copied from django/trunk/django/conf/locale/nl/LC_MESSAGES/django.mo)
- django/branches/magic-removal/django/conf/locale/nl/LC_MESSAGES/django.po (copied) (copied from django/trunk/django/conf/locale/nl/LC_MESSAGES/django.po)
- django/branches/magic-removal/django/conf/project_template/settings.py (modified) (1 diff)
- django/branches/magic-removal/django/core/mail.py (modified) (1 diff)
- django/branches/magic-removal/docs/email.txt (modified) (3 diffs)
- django/branches/magic-removal/docs/settings.txt (modified) (1 diff)
- django/branches/magic-removal/docs/templates_python.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/django/conf/project_template/settings.py
r1678 r1810 61 61 TEMPLATE_DIRS = ( 62 62 # Put strings here, like "/home/html/django_templates". 63 # Always use forward slashes, even on Windows. 63 64 ) 64 65 django/branches/magic-removal/django/core/mail.py
r1796 r1810 5 5 import smtplib 6 6 7 class BadHeaderError(ValueError): 8 pass 9 7 10 class SafeMIMEText(MIMEText): 8 11 def __setitem__(self, name, val): 9 12 "Forbids multi-line headers, to prevent header injection." 10 13 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) 12 15 MIMEText.__setitem__(self, name, val) 13 16 django/branches/magic-removal/docs/email.txt
r1796 r1810 128 128 by forbidding newlines in header values. If any ``subject``, ``from_email`` or 129 129 ``recipient_list`` contains a newline, the e-mail function (e.g. 130 ``send_mail()``) will raise `` ValueError`` and, hence, will not send the131 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 132 to validate all data before passing it to the e-mail functions. 133 133 134 134 Here's an example view that takes a ``subject``, ``message`` and ``from_email`` … … 136 136 "/contact/thanks/" when it's done:: 137 137 138 from django.core.mail import send_mail 138 from django.core.mail import send_mail, BadHeaderError 139 139 140 140 def send_email(request): … … 142 142 message = request.POST.get('message', '') 143 143 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.') 148 149 return HttpResponseRedirect('/contact/thanks/') 149 150 else: django/branches/magic-removal/docs/settings.txt
r1775 r1810 585 585 Default: ``()`` (Empty tuple) 586 586 587 List of locations of the template source files, in search order. See the 588 `template documentation`_. 587 List of locations of the template source files, in search order. Note that 588 these paths should use Unix-style forward slashes, even on Windows. 589 590 See the `template documentation`_. 589 591 590 592 TEMPLATE_FILE_EXTENSION django/branches/magic-removal/docs/templates_python.txt
r1775 r1810 389 389 ) 390 390 391 Note that these paths should use Unix-style forward slashes, even on Windows. 392 391 393 The Python API 392 394 ~~~~~~~~~~~~~~
