mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Postmark: handle Reply-To in EmailMessage headers
Move 'Reply-To' header into dedicated Postmark API param Fixes #39
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import re
|
||||
|
||||
from requests.structures import CaseInsensitiveDict
|
||||
|
||||
from ..exceptions import AnymailRequestsAPIError
|
||||
from ..message import AnymailRecipientStatus
|
||||
from ..utils import get_anymail_setting
|
||||
@@ -140,9 +142,12 @@ class PostmarkPayload(RequestsPayload):
|
||||
self.data["ReplyTo"] = reply_to
|
||||
|
||||
def set_extra_headers(self, headers):
|
||||
header_dict = CaseInsensitiveDict(headers)
|
||||
if 'Reply-To' in header_dict:
|
||||
self.data["ReplyTo"] = header_dict.pop('Reply-To')
|
||||
self.data["Headers"] = [
|
||||
{"Name": key, "Value": value}
|
||||
for key, value in headers.items()
|
||||
for key, value in header_dict.items()
|
||||
]
|
||||
|
||||
def set_text_body(self, body):
|
||||
|
||||
@@ -85,9 +85,9 @@ class PostmarkBackendStandardEmailTests(PostmarkBackendMockAPITestCase):
|
||||
self.assertEqual(data['To'], 'to1@example.com, Also To <to2@example.com>')
|
||||
self.assertEqual(data['Bcc'], 'bcc1@example.com, Also BCC <bcc2@example.com>')
|
||||
self.assertEqual(data['Cc'], 'cc1@example.com, Also CC <cc2@example.com>')
|
||||
self.assertEqual(data['ReplyTo'], 'another@example.com')
|
||||
self.assertCountEqual(data['Headers'], [
|
||||
{'Name': 'Message-ID', 'Value': 'mycustommsgid@sales.example.com'},
|
||||
{'Name': 'Reply-To', 'Value': 'another@example.com'},
|
||||
{'Name': 'X-MyHeader', 'Value': 'my value'},
|
||||
])
|
||||
|
||||
@@ -136,6 +136,16 @@ class PostmarkBackendStandardEmailTests(PostmarkBackendMockAPITestCase):
|
||||
self.assertEqual(data['ReplyTo'], 'reply@example.com, Other <reply2@example.com>')
|
||||
self.assertEqual(data['Headers'], [{'Name': 'X-Other', 'Value': 'Keep'}]) # don't lose other headers
|
||||
|
||||
def test_reply_to_header(self):
|
||||
# Reply-To needs to be moved out of headers, into dedicated param
|
||||
email = mail.EmailMessage('Subject', 'Body goes here', 'from@example.com', ['to1@example.com'],
|
||||
headers={'reply-to': 'reply@example.com, Other <reply2@example.com>',
|
||||
'X-Other': 'Keep'})
|
||||
email.send()
|
||||
data = self.get_api_call_json()
|
||||
self.assertEqual(data['ReplyTo'], 'reply@example.com, Other <reply2@example.com>')
|
||||
self.assertEqual(data['Headers'], [{'Name': 'X-Other', 'Value': 'Keep'}]) # don't lose other headers
|
||||
|
||||
def test_attachments(self):
|
||||
text_content = "* Item one\n* Item two\n* Item three"
|
||||
self.message.attach(filename="test.txt", content=text_content, mimetype="text/plain")
|
||||
|
||||
Reference in New Issue
Block a user