Postmark: handle Reply-To in EmailMessage headers

Move 'Reply-To' header into dedicated Postmark API param

Fixes #39
This commit is contained in:
medmunds
2016-11-01 12:12:21 -07:00
parent e78410eea4
commit 4ca39a976f
2 changed files with 17 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
import re import re
from requests.structures import CaseInsensitiveDict
from ..exceptions import AnymailRequestsAPIError from ..exceptions import AnymailRequestsAPIError
from ..message import AnymailRecipientStatus from ..message import AnymailRecipientStatus
from ..utils import get_anymail_setting from ..utils import get_anymail_setting
@@ -140,9 +142,12 @@ class PostmarkPayload(RequestsPayload):
self.data["ReplyTo"] = reply_to self.data["ReplyTo"] = reply_to
def set_extra_headers(self, headers): 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"] = [ self.data["Headers"] = [
{"Name": key, "Value": value} {"Name": key, "Value": value}
for key, value in headers.items() for key, value in header_dict.items()
] ]
def set_text_body(self, body): def set_text_body(self, body):

View File

@@ -85,9 +85,9 @@ class PostmarkBackendStandardEmailTests(PostmarkBackendMockAPITestCase):
self.assertEqual(data['To'], 'to1@example.com, Also To <to2@example.com>') 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['Bcc'], 'bcc1@example.com, Also BCC <bcc2@example.com>')
self.assertEqual(data['Cc'], 'cc1@example.com, Also CC <cc2@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'], [ self.assertCountEqual(data['Headers'], [
{'Name': 'Message-ID', 'Value': 'mycustommsgid@sales.example.com'}, {'Name': 'Message-ID', 'Value': 'mycustommsgid@sales.example.com'},
{'Name': 'Reply-To', 'Value': 'another@example.com'},
{'Name': 'X-MyHeader', 'Value': 'my value'}, {'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['ReplyTo'], 'reply@example.com, Other <reply2@example.com>')
self.assertEqual(data['Headers'], [{'Name': 'X-Other', 'Value': 'Keep'}]) # don't lose other headers 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): def test_attachments(self):
text_content = "* Item one\n* Item two\n* Item three" text_content = "* Item one\n* Item two\n* Item three"
self.message.attach(filename="test.txt", content=text_content, mimetype="text/plain") self.message.attach(filename="test.txt", content=text_content, mimetype="text/plain")