Cleanup: centralize Reply-To header handling; case-insensitive headers

Django allows setting the reply address with either message.reply_to
or message.extra_headers["Reply-To"]. If both are supplied, the extra
headers version takes precedence. (See EmailMessage.message().)

Several Anymail backends had duplicate logic to handle conflicting
properties. Move that logic into the base Payload.

(Also prepares for common handling of extra_headers['From'], later.)

Related changes:

* Use CaseInsensitiveDict for processing extra_headers.
  This is potentially a breaking change, but any code that was trying
  to send multiple headers differing only in case was likely already
  broken. (Email header field names are case-insensitive, per RFC-822.)

* Handle CaseInsensitiveDict in RequestsPayload.serialize_json().
  (Several backends had duplicate code for handling this, too.)

* Fixes SparkPost backend, which had been incorrectly treating
  message.reply_to and message.extra_headers['Reply-To'] differently.
This commit is contained in:
medmunds
2018-02-26 12:02:48 -08:00
parent ec0ee336a2
commit bd9d92f5a0
9 changed files with 75 additions and 33 deletions

View File

@@ -147,7 +147,7 @@ class SparkPostPayload(BasePayload):
def set_extra_headers(self, headers):
if headers:
self.params['custom_headers'] = headers
self.params['custom_headers'] = dict(headers) # convert CaseInsensitiveDict to plain dict for SP lib
def set_text_body(self, body):
self.params['text'] = body