Skip to content

Commit 98ce706

Browse files
arturfsousarichleland
authored andcommitted
Reusing subdata from the first recipient
Note that this will include `substitution_data`, `metadata`, and `tags` from the first recipient. * Keep substitution data for cc/bcc * Re-enable ensure_ascii for json.dumps, fixes #128
1 parent cbb5827 commit 98ce706

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

sparkpost/transmissions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import copy
23
import json
34
from email.utils import parseaddr
45

@@ -90,10 +91,13 @@ def _format_copies(self, recipients, copies):
9091
formatted_copies = []
9192
if len(recipients) > 0:
9293
formatted_copies = self._extract_recipients(copies)
94+
main_recipient = copy.deepcopy(recipients[0])
95+
main_recipient.pop('address')
9396
for recipient in formatted_copies:
9497
recipient['address'].update({
9598
'header_to': self._format_header_to(recipients[0])
9699
})
100+
recipient.update(**main_recipient)
97101
return formatted_copies
98102

99103
def _format_header_to(self, recipient):
@@ -241,8 +245,7 @@ def send(self, **kwargs):
241245
"""
242246

243247
payload = self._translate_keys(**kwargs)
244-
results = self.request('POST', self.uri,
245-
data=json.dumps(payload, ensure_ascii=False))
248+
results = self.request('POST', self.uri, data=json.dumps(payload))
246249
return results
247250

248251
def _fetch_get(self, transmission_id):

test/test_transmissions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def test_cc_with_sub_data():
8989
'address': {
9090
'email': '[email protected]',
9191
'header_to': '[email protected]'
92-
}
92+
},
93+
'substitution_data': {'fake': 'data'}
9394
}
9495
]
9596

0 commit comments

Comments
 (0)