Skip to content

Commit

Permalink
Reusing subdata from the first recipient
Browse files Browse the repository at this point in the history
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
  • Loading branch information
arturfsousa authored and richleland committed Nov 14, 2016
1 parent cbb5827 commit 98ce706
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions sparkpost/transmissions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import copy
import json
from email.utils import parseaddr

Expand Down Expand Up @@ -90,10 +91,13 @@ def _format_copies(self, recipients, copies):
formatted_copies = []
if len(recipients) > 0:
formatted_copies = self._extract_recipients(copies)
main_recipient = copy.deepcopy(recipients[0])
main_recipient.pop('address')
for recipient in formatted_copies:
recipient['address'].update({
'header_to': self._format_header_to(recipients[0])
})
recipient.update(**main_recipient)
return formatted_copies

def _format_header_to(self, recipient):
Expand Down Expand Up @@ -241,8 +245,7 @@ def send(self, **kwargs):
"""

payload = self._translate_keys(**kwargs)
results = self.request('POST', self.uri,
data=json.dumps(payload, ensure_ascii=False))
results = self.request('POST', self.uri, data=json.dumps(payload))
return results

def _fetch_get(self, transmission_id):
Expand Down
3 changes: 2 additions & 1 deletion test/test_transmissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def test_cc_with_sub_data():
'address': {
'email': 'ccone@example.com',
'header_to': 'primary@example.com'
}
},
'substitution_data': {'fake': 'data'}
}
]

Expand Down

0 comments on commit 98ce706

Please sign in to comment.