Example #1
0
    def test_encrypt_decrypt_mime_mixed(self, account_maker):
        acc1, acc2 = account_maker(), account_maker()

        # send a mail from addr1 with autocrypt key to addr2
        acc2.process_incoming(gen_ac_mail_msg(acc1, acc2))

        # create a multipart/mixed mail
        msg2 = gen_ac_mail_msg(acc2, acc1, payload=[])
        msg2.attach(mime.make_message('text/plain', payload="some text"))
        img = MIMEImage(b'\003\005', "jpeg")
        img['Content-Disposition'] = 'attachment; filename="x.jpg"'
        msg2.attach(img)

        # send multipart/mixed back to acc1
        r = acc2.encrypt_mime(msg2, [acc1.addr])
        acc1.process_incoming(r.enc_msg)

        # decrypt the incoming mail
        r = acc1.decrypt_mime(r.enc_msg)
        dec = r.dec_msg
        assert dec.get_content_type() == "multipart/mixed"
        assert len(dec.get_payload()) == 2
        m1, m2 = dec.get_payload()
        assert m1.get_content_type() == msg2.get_payload()[0].get_content_type(
        )
        assert m2.get_content_type() == img.get_content_type()
        assert m2.get_payload(decode=True) == img.get_payload(decode=True)
Example #2
0
def tag_ogg(target_file, info):

    tag = vorbis.VorbisComment()
    tag['GENRE'] = str(info['genre'])
    tag['ALBUM'] = str(info['album'])
    tag['TITLE'] = str(info['title'])
    tag['COMMENTS'] = str(info['comment'])
    tag['ARTIST'] = str(info['artist'])
    tag['DATE'] = str(localtime().tm_year)
    tag['TRACKNUMBER'] = '1'

    # OK, now try importing the image
    try:
        fp = open(info['image'], 'rb')
        img = MIMEImage(fp.read())
        tag['COVERARTMIME'] = img.get_content_type()
        tag['COVERART'] = (img.get_payload())
        tag['COVERART']
    except:
        print "Cannot open Image file"
        return

    if tag['COVERARTMIME']:
        try:
            target = target_file + '.ogg'
            tag.write_to(target)
        except:
            print "Can't write to .ogg file"
            return
Example #3
0
 def test_send_smtp_inline_images(self, mock_send_mime):
     image = read_fixture('sample.png')
     utils.send_email_smtp(
         'to', 'subject', 'content', app.config, images=dict(blah=image))
     assert mock_send_mime.called
     call_args = mock_send_mime.call_args[0]
     logging.debug(call_args)
     assert call_args[0] == app.config.get('SMTP_MAIL_FROM')
     assert call_args[1] == ['to']
     msg = call_args[2]
     assert msg['Subject'] == 'subject'
     assert msg['From'] == app.config.get('SMTP_MAIL_FROM')
     assert len(msg.get_payload()) == 2
     mimeapp = MIMEImage(image)
     assert msg.get_payload()[-1].get_payload() == mimeapp.get_payload()
Example #4
0
 def test_send_smtp_inline_images(self, mock_send_mime):
     image = read_fixture("sample.png")
     utils.send_email_smtp(
         "to", "subject", "content", app.config, images=dict(blah=image)
     )
     assert mock_send_mime.called
     call_args = mock_send_mime.call_args[0]
     logger.debug(call_args)
     assert call_args[0] == app.config["SMTP_MAIL_FROM"]
     assert call_args[1] == ["to"]
     msg = call_args[2]
     assert msg["Subject"] == "subject"
     assert msg["From"] == app.config["SMTP_MAIL_FROM"]
     assert len(msg.get_payload()) == 2
     mimeapp = MIMEImage(image)
     assert msg.get_payload()[-1].get_payload() == mimeapp.get_payload()
Example #5
0
    def test_backend_image_attachments(self):
        message = EmailMessage('subject', 'body', '*****@*****.**',
                               ['*****@*****.**'])

        filename = os.path.join(os.path.dirname(__file__), 'static/dummy.png')
        fileobj = File(open(filename, 'rb'), name='dummy.png')
        image = MIMEImage(fileobj.read())
        image.add_header('Content-Disposition', 'inline', filename='dummy.png')
        image.add_header('Content-ID', '<{dummy.png}>')
        message.attach(image)
        message.send()

        email = Email.objects.latest('id')
        self.assertEqual(email.attachments.count(), 1)
        self.assertEqual(email.attachments.all()[0].name, 'dummy.png')
        self.assertEqual(email.attachments.all()[0].file.read(), image.get_payload().encode())
        self.assertEqual(email.attachments.all()[0].headers.get('Content-ID'), '<{dummy.png}>')
        self.assertEqual(email.attachments.all()[0].headers.get('Content-Disposition'), 'inline; filename="dummy.png"')
Example #6
0
    def test_backend_image_attachments(self):
        message = EmailMessage('subject', 'body', '*****@*****.**',
                               ['*****@*****.**'])

        filename = os.path.join(os.path.dirname(__file__), 'static/dummy.png')
        fileobj = File(open(filename, 'rb'), name='dummy.png')
        image = MIMEImage(fileobj.read())
        image.add_header('Content-Disposition', 'inline', filename='dummy.png')
        image.add_header('Content-ID', '<{dummy.png}>')
        message.attach(image)
        message.send()

        email = Email.objects.latest('id')
        self.assertEqual(email.attachments.count(), 1)
        self.assertEqual(email.attachments.all()[0].name, 'dummy.png')
        self.assertEqual(email.attachments.all()[0].file.read(), image.get_payload().encode())
        self.assertEqual(email.attachments.all()[0].headers.get('Content-ID'), '<{dummy.png}>')
        self.assertEqual(email.attachments.all()[0].headers.get('Content-Disposition'), 'inline; filename="dummy.png"')