mirror of
https://github.com/django/django.git
synced 2024-11-19 07:54:07 +00:00
70b6c4c015
email messages. Previously we were creating duplicate headers, which was bad. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9197 bcc190cf-cafb-0310-a4f2-bffc1f526a37
64 lines
2.6 KiB
Python
64 lines
2.6 KiB
Python
# coding: utf-8
|
|
r"""
|
|
# Tests for the django.core.mail.
|
|
|
|
>>> from django.core.mail import EmailMessage
|
|
>>> from django.utils.translation import ugettext_lazy
|
|
|
|
# Test normal ascii character case:
|
|
|
|
>>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'])
|
|
>>> message = email.message()
|
|
>>> message['Subject'].encode()
|
|
'Subject'
|
|
>>> message.get_payload()
|
|
'Content'
|
|
>>> message['From']
|
|
'from@example.com'
|
|
>>> message['To']
|
|
'to@example.com'
|
|
|
|
# Test multiple-recipient case
|
|
|
|
>>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com','other@example.com'])
|
|
>>> message = email.message()
|
|
>>> message['Subject'].encode()
|
|
'Subject'
|
|
>>> message.get_payload()
|
|
'Content'
|
|
>>> message['From']
|
|
'from@example.com'
|
|
>>> message['To']
|
|
'to@example.com, other@example.com'
|
|
|
|
# Test for header injection
|
|
|
|
>>> email = EmailMessage('Subject\nInjection Test', 'Content', 'from@example.com', ['to@example.com'])
|
|
>>> message = email.message()
|
|
Traceback (most recent call last):
|
|
...
|
|
BadHeaderError: Header values can't contain newlines (got u'Subject\nInjection Test' for header 'Subject')
|
|
|
|
>>> email = EmailMessage(ugettext_lazy('Subject\nInjection Test'), 'Content', 'from@example.com', ['to@example.com'])
|
|
>>> message = email.message()
|
|
Traceback (most recent call last):
|
|
...
|
|
BadHeaderError: Header values can't contain newlines (got u'Subject\nInjection Test' for header 'Subject')
|
|
|
|
# Test for space continuation character in long (ascii) subject headers (#7747)
|
|
|
|
>>> email = EmailMessage('Long subject lines that get wrapped should use a space continuation character to get expected behaviour in Outlook and Thunderbird', 'Content', 'from@example.com', ['to@example.com'])
|
|
>>> message = email.message()
|
|
>>> message.as_string()
|
|
'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: Long subject lines that get wrapped should use a space continuation\n character to get expected behaviour in Outlook and Thunderbird\nFrom: from@example.com\nTo: to@example.com\nDate: ...\nMessage-ID: <...>\n\nContent'
|
|
|
|
# Specifying dates or message-ids in the extra headers overrides the defaul
|
|
# values (#9233).
|
|
|
|
>>> headers = {"date": "Fri, 09 Nov 2001 01:08:47 -0000", "Message-ID": "foo"}
|
|
>>> email = EmailMessage('subject', 'content', 'from@example.com', ['to@example.com'], headers=headers)
|
|
>>> email.message().as_string()
|
|
'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: subject\nFrom: from@example.com\nTo: to@example.com\ndate: Fri, 09 Nov 2001 01:08:47 -0000\nMessage-ID: foo\n\ncontent'
|
|
|
|
"""
|