From 734376f9473693b87db0bdc30a725500db0fb181 Mon Sep 17 00:00:00 2001
From: Jacob Kaplan-Moss <jacob@jacobian.org>
Date: Tue, 24 Feb 2009 17:02:03 +0000
Subject: [PATCH] [1.0.X] Fixed #9214: EmailMessage now respects the From
 header instead of blindly using from_email. Thanks, Tai Lee.

Backport of r9842 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9900 bcc190cf-cafb-0310-a4f2-bffc1f526a37
---
 django/core/mail.py                 | 2 +-
 tests/regressiontests/mail/tests.py | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/django/core/mail.py b/django/core/mail.py
index 58588bf712..157474ff2c 100644
--- a/django/core/mail.py
+++ b/django/core/mail.py
@@ -245,7 +245,7 @@ class EmailMessage(object):
                 else:
                     msg.attach(self._create_attachment(*attachment))
         msg['Subject'] = self.subject
-        msg['From'] = self.from_email
+        msg['From'] = self.extra_headers.pop('From', self.from_email)
         msg['To'] = ', '.join(self.to)
 
         # Email header names are case-insensitive (RFC 2045), so we have to
diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
index c2c084c4c6..083840f45e 100644
--- a/tests/regressiontests/mail/tests.py
+++ b/tests/regressiontests/mail/tests.py
@@ -60,4 +60,11 @@ BadHeaderError: Header values can't contain newlines (got u'Subject\nInjection T
 >>> 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'
 
+# Make sure we can manually set the From header (#9214)
+
+>>> email = EmailMessage('Subject', 'Content', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'}) 
+>>> message = email.message() 
+>>> message['From']
+'from@example.com'
+
 """