Skip to content

Commit

Permalink
Merge 2680178 into c55a461
Browse files Browse the repository at this point in the history
  • Loading branch information
tuck1s committed Nov 2, 2018
2 parents c55a461 + 2680178 commit 6c35033
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 21 deletions.
46 changes: 25 additions & 21 deletions sparkpost/transmissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,31 @@ def _translate_keys(self, **kwargs):
model['options']['ip_pool'] = kwargs.get('ip_pool')
model['options']['inline_css'] = kwargs.get('inline_css')

model['content']['use_draft_template'] = \
kwargs.get('use_draft_template', False)
model['content']['reply_to'] = kwargs.get('reply_to')
model['content']['subject'] = kwargs.get('subject')
from_email = kwargs.get('from_email')
if isinstance(from_email, string_types):
from_email = self._parse_address(from_email)
model['content']['from'] = from_email
model['content']['html'] = kwargs.get('html')
model['content']['text'] = kwargs.get('text')
model['content']['template_id'] = kwargs.get('template')
model['content']['headers'] = kwargs.get('custom_headers', {})
rfc822 = kwargs.get('email_rfc822')
if rfc822:
model['content']['email_rfc822'] = rfc822
else:
model['content']['headers'] = kwargs.get('custom_headers', {})
model['content']['use_draft_template'] = \
kwargs.get('use_draft_template', False)
model['content']['reply_to'] = kwargs.get('reply_to')
model['content']['subject'] = kwargs.get('subject')
from_email = kwargs.get('from_email')
if isinstance(from_email, string_types):
from_email = self._parse_address(from_email)
model['content']['from'] = from_email
model['content']['html'] = kwargs.get('html')
model['content']['text'] = kwargs.get('text')
model['content']['template_id'] = kwargs.get('template')

attachments = kwargs.get('attachments', [])
model['content']['attachments'] = self._extract_attachments(
attachments)

if 'inline_images' in kwargs:
inline_images = kwargs['inline_images']
model['content']['inline_images'] = self._extract_attachments(
inline_images)

recipient_list = kwargs.get('recipient_list')
if recipient_list:
Expand All @@ -77,15 +90,6 @@ def _translate_keys(self, **kwargs):

model['recipients'] = recipients

attachments = kwargs.get('attachments', [])
model['content']['attachments'] = self._extract_attachments(
attachments)

if 'inline_images' in kwargs:
inline_images = kwargs['inline_images']
model['content']['inline_images'] = self._extract_attachments(
inline_images)

return model

def _format_copies(self, recipients, copies):
Expand Down
33 changes: 33 additions & 0 deletions test/test_transmissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,39 @@ def test_translate_keys_with_inline_css():
assert results['options'].get('inline_css') is True


def test_translate_keys_with_email_rfc822():
t = Transmissions('uri', 'key')

# Build data using implicit cat, as max line length is enforced
eml = (
'To: wilma <wilma@flintstone.com>\n',
'From: fred <fred@flintstone.com>\n',
'Subject: Bedrock declaration\n',
'MIME-Version: 1.0\n',
'Content-Type: text/plain; charset=utf-8; format=flowed\n',
'Content-Transfer-Encoding: 7bit\nContent-Language: en-GB\n',
'\n',
'When in the Course of human events we yell yabba dabba doo.',
)

# Just a selection. Don't test attribs with irregular naming
non_rfc822_attrs = {
'headers': 'foo',
'reply_to': 'foo',
'subject': 'foo',
'html': 'foo',
'text': 'foo',
}

# Demonstrate that email_rfc822 overrides other content attributes
test_content = {'email_rfc822': eml}
test_content.update(non_rfc822_attrs)
results = t._translate_keys(**test_content)
for i in non_rfc822_attrs:
assert results['content'].get(i) is None
assert results['content'].get('email_rfc822') is not None


@responses.activate
def test_success_send():
responses.add(
Expand Down

0 comments on commit 6c35033

Please sign in to comment.