'Regression test for #9367'

def test_attachments(self):

    headers = {u'Date': u'Fri,    09    Nov    2001    01:08:47    -0000', u'Message-ID': u'foo'}
    (subject, from_email, to) = (u'hello', u'from@example.com', u'to@example.com')
    text_content = u'This    is    an    important    message.'
    html_content = u'<p>This    is    an    <strong>important</strong>    message.</p>'
    msg = EmailMultiAlternatives(subject, text_content, from_email, [to], headers=headers)
    msg.attach_alternative(html_content, u'text/html')
    msg.attach(u'an    attachment.pdf', '%PDF-1.4.%...', mimetype=u'application/pdf')
    msg_bytes = msg.message().as_bytes()
    message = message_from_bytes(msg_bytes)
    self.assertTrue(message.is_multipart())
    self.assertEqual(message.get_content_type(), u'multipart/mixed')
    self.assertEqual(message.get_default_type(), u'text/plain')
    payload = message.get_payload()
    self.assertEqual(payload[0].get_content_type(), u'multipart/alternative')
    self.assertEqual(payload[1].get_content_type(), u'application/pdf')
