Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13259 -- Ensure that multiple calls to message() don't corrupt…

… any extra message headers. Thanks to canburak for the report, and Andi Albrecht for the fix.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12901 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit db5be42c124886eab758e5f4c181db32af174e23 1 parent 271bcda
Russell Keith-Magee authored April 01, 2010
4  django/core/mail/message.py
@@ -143,7 +143,7 @@ def message(self):
143 143
                            self.content_subtype, encoding)
144 144
         msg = self._create_message(msg)
145 145
         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)
147 147
         msg['To'] = ', '.join(self.to)
148 148
 
149 149
         # Email header names are case-insensitive (RFC 2045), so we have to
@@ -154,6 +154,8 @@ def message(self):
154 154
         if 'message-id' not in header_names:
155 155
             msg['Message-ID'] = make_msgid()
156 156
         for name, value in self.extra_headers.items():
  157
+            if name.lower() == 'from':  # From is already handled
  158
+                continue
157 159
             msg[name] = value
158 160
         return msg
159 161
 
10  tests/regressiontests/mail/tests.py
@@ -101,6 +101,16 @@
101 101
 >>> message['From']
102 102
 'from@example.com'
103 103
 
  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
+
104 114
 # Regression for #11144 - When a to/from/cc header contains unicode,
105 115
 # make sure the email addresses are parsed correctly (especially
106 116
 # with regards to commas)

0 notes on commit db5be42

Please sign in to comment.
Something went wrong with that request. Please try again.