Пример #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)
Пример #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