mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
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:
@@ -3,7 +3,7 @@ from requests.structures import CaseInsensitiveDict
|
||||
from .base_requests import AnymailRequestsBackend, RequestsPayload
|
||||
from ..exceptions import AnymailRequestsAPIError
|
||||
from ..message import AnymailRecipientStatus
|
||||
from ..utils import get_anymail_setting, parse_address_list
|
||||
from ..utils import get_anymail_setting
|
||||
|
||||
|
||||
class EmailBackend(AnymailRequestsBackend):
|
||||
@@ -88,15 +88,8 @@ class SendinBluePayload(RequestsPayload):
|
||||
def serialize_data(self):
|
||||
"""Performs any necessary serialization on self.data, and returns the result."""
|
||||
|
||||
headers = self.data["headers"]
|
||||
if "Reply-To" in headers:
|
||||
# Reply-To must be in its own param
|
||||
reply_to = headers.pop('Reply-To')
|
||||
self.set_reply_to(parse_address_list([reply_to]))
|
||||
if len(headers) > 0:
|
||||
self.data["headers"] = dict(headers) # flatten to normal dict for json serialization
|
||||
else:
|
||||
del self.data["headers"] # don't send empty headers
|
||||
if not self.data['headers']:
|
||||
del self.data['headers'] # don't send empty headers
|
||||
|
||||
# SendinBlue use different argument's name if we use template functionality
|
||||
if self.template_id:
|
||||
@@ -179,8 +172,7 @@ class SendinBluePayload(RequestsPayload):
|
||||
self.data['replyTo'] = self.email_object(emails[0])
|
||||
|
||||
def set_extra_headers(self, headers):
|
||||
for key in headers.keys():
|
||||
self.data['headers'][key] = headers[key]
|
||||
self.data['headers'].update(headers)
|
||||
|
||||
def set_tags(self, tags):
|
||||
if len(tags) > 0:
|
||||
|
||||
Reference in New Issue
Block a user