def test_respond_attach(): dude = "hello" mail = view.respond(locals(), Body="template.txt", From="test@localhost", To="receiver@localhost", Subject='Test body from someone.') view.attach(mail, locals(), 'template.html', content_type="text/html", filename="template.html", disposition='attachment') assert_equal(len(mail.attachments), 1) msg = mail.to_message() assert_equal(len(msg.get_payload()), 2) assert str(msg) mail.clear() view.attach(mail, locals(), 'template.html', content_type="text/html") assert_equal(len(mail.attachments), 1) msg = mail.to_message() assert_equal(len(msg.get_payload()), 2) assert str(msg)
def UPLOADPK(msg, address=None, host=None): res={} sender=collapse_rfc2231_value(msg['from']) m=sendere.match(sender) if m: res['sender_name'], res['sender_mail']=m.groups() else: res['sender_mail']=sender for mpart in msg.walk(): ispgp=False part=to_message(mpart) if part.get_content_type()=='text/plain': # cut of preamble inblock=False lines=part.get_payload(decode=True).split('\n') i=0 while i<len(lines): if not inblock: if lines[i].strip()=='-----BEGIN PGP PUBLIC KEY BLOCK-----': inblock=True i+=2 else: if lines[i].strip()=='-----END PGP PUBLIC KEY BLOCK-----': break i+=1 if i<len(lines): ispgp=True elif part.get_content_type()=='application/pgp-keys': ispgp=True if ispgp: res=getpgpmeta(part.get_payload(decode=True)) ret=gpg('--import', _err_to_out=True, _in=part.get_payload(decode=True)) #logging.info(ret) modifiers={'fresh': False, 'abbreved': False, 'singleid': False, 'tidy': False, } if res['datetime']>datetime.datetime.utcnow()-datetime.timedelta(days=10): modifiers['fresh']=True if len(res['ids'])<2: modifiers['singleid']=True if len(res['ids'][0]['email'].split('@')[0])<9: modifiers['abbreved']=True if len([1 for x in res['sigs'] if x['st'] not in ['Positive certification of a User ID and Public Key packet', 'Subkey Binding Signature']])==0: modifiers['tidy']=True res['award']=award("You uploaded your public key.\n%s" % '\n'.join(["%s [%s]" % (k,'X' if v else ' ') for k,v in modifiers.items()])) #logging.info(res) welcome = view.respond(res, "pkuploaded.msg", From=sendermail, To=sender, Subject="Welcome to the Privacy Challenge") view.attach(welcome, {}, "pubkey.asc", filename="my key", content_type="application/pgp-keys") relay.deliver(welcome)
def test_unicode(): dude = u'H\xe9avy M\xe9t\xe5l Un\xeec\xf8d\xe9' mail = view.respond(locals(), Html="unicode.html", From="test@localhost", To="receiver@localhost", Subject='Test body from someone.') assert str(mail) view.attach(mail, locals(), "unicode.html", filename="attached.html") assert str(mail)