Ticket #9214: 9214-EmailMessage-r9084.diff

File 9214-EmailMessage-r9084.diff, 1.8 KB (added by Tai Lee, 16 years ago)

Working patch with test.

  • django/core/mail.py

     
    245245                else:
    246246                    msg.attach(self._create_attachment(*attachment))
    247247        msg['Subject'] = self.subject
    248         msg['From'] = self.from_email
     248        msg['From'] = self.extra_headers.get('From', self.from_email)
    249249        msg['To'] = ', '.join(self.to)
    250250        msg['Date'] = formatdate()
    251251        msg['Message-ID'] = make_msgid()
    252252        for name, value in self.extra_headers.items():
    253             msg[name] = value
     253            if name != 'From':
     254                msg[name] = value
    254255        return msg
    255256
    256257    def recipients(self):
  • tests/regressiontests/mail/tests.py

     
    5252>>> message.as_string()
    5353'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'
    5454
     55# Test override of From header (#9214).
     56
     57>>> email = EmailMessage('Subject', 'Content', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'})
     58>>> message = email.message()
     59>>> message.as_string()
     60'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: ...\nMessage-ID: <...>\n\nContent'
     61
    5562"""
Back to Top