Ticket #13259: trac13259.diff

File trac13259.diff, 1.8 KB (added by Andi Albrecht, 15 years ago)
  • django/core/mail/message.py

    diff --git a/django/core/mail/message.py b/django/core/mail/message.py
    index a288d6c..91a10a0 100644
    a b class EmailMessage(object):  
    143143                           self.content_subtype, encoding)
    144144        msg = self._create_message(msg)
    145145        msg['Subject'] = self.subject
    146         msg['From'] = self.extra_headers.pop('From', self.from_email)
     146        msg['From'] = self.extra_headers.get('From', self.from_email)
    147147        msg['To'] = ', '.join(self.to)
    148148
    149149        # Email header names are case-insensitive (RFC 2045), so we have to
    class EmailMessage(object):  
    154154        if 'message-id' not in header_names:
    155155            msg['Message-ID'] = make_msgid()
    156156        for name, value in self.extra_headers.items():
     157            if name.lower() == 'from':  # From is already handled
     158                continue
    157159            msg[name] = value
    158160        return msg
    159161
  • tests/regressiontests/mail/tests.py

    diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
    index e27804c..84be585 100644
    a b BadHeaderError: Header values can't contain newlines (got u'Subject\nInjection T  
    101101>>> message['From']
    102102'from@example.com'
    103103
     104# Regression for #13259 - Make sure that headers are not changed
     105# when calling EmailMessage.message()
     106>>> email = EmailMessage('Subject', 'Content', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'})
     107>>> message = email.message()
     108>>> message['From']
     109'from@example.com'
     110>>> message = email.message()
     111>>> message['From']
     112'from@example.com'
     113
    104114# Regression for #11144 - When a to/from/cc header contains unicode,
    105115# make sure the email addresses are parsed correctly (especially
    106116# with regards to commas)
Back to Top