Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_unsupported_content_types():
params = get_params()
with pytest.raises(UnsupportedContent):
mail = EmailMultiAlternatives(
params['subject'],
'plain text',
params['from_email'],
params['recipient_list'])
mail.attach_alternative('non-plain content', 'text/alien')
mail.send()
if message.cc:
formatted['cc'] = message.cc
if message.bcc:
formatted['bcc'] = message.bcc
if hasattr(message, 'reply_to') and message.reply_to:
formatted['reply_to'] = ','.join(message.reply_to)
if isinstance(message, EmailMultiAlternatives):
for alternative in message.alternatives:
if alternative[1] == 'text/html':
formatted['html'] = alternative[0]
else:
raise UnsupportedContent(
'Content type %s is not supported' % alternative[1]
)
if message.attachments:
formatted['attachments'] = []
str_encoding = settings.DEFAULT_CHARSET
for attachment in message.attachments:
filename, content, mimetype = attachment
if mimetype is None:
mimetype, _ = mimetypes.guess_type(filename)
if mimetype is None:
mimetype = DEFAULT_ATTACHMENT_MIME_TYPE
try:
if isinstance(content, unicode):