Example #1
0
logging.basicConfig(filename=PATH_log,level=logging.INFO)
log = logging.getLogger('postoffice.inbox')

queued = os.listdir(PATH_queue)
for filename in queued:
    try:
        filepath = os.path.join(PATH_queue,filename)
        l = letter.letter()
        l.read(os.path.join(filepath))
        r = process_letter(l)
        
        ret = letter.letter()
        ret.attributes = {'TAG':l.attributes['TAG'],'VIA':l.attributes['VIA'],'SENDER':l.attributes['SENDER'],'RECEIVER':l.attributes['RECEIVER']}

        for i in r:
            ret.body += i + '\n\r'

        outputfilename = os.path.join(PATH_handled,l.attributes['VIA'] + '.' + uniqid())
        ret.write(outputfilename)

        log.info('Handled one letter: [%s] to [%s] via [%s] tagged [%s].',
            l.attributes['SENDER'],l.attributes['RECEIVER'],l.attributes['VIA'],l.attributes['TAG'])

    except Exception,e:
        
        log.exception("Error processing letter: %s",e)

        # Move to failed
        shutil.copy(filepath,os.path.join(PATH_error,filename))
    os.remove(filepath)
Example #2
0
    holder.load_public_text  ( open( os.path.join(_util.BASEPATH,publiclist[signtarget]) ,'r').read() )

    def _pinreader(b=False,p1='',p2=''):
        msg = '即将签署以下证书:\n [%s]\n ' % signtarget
        msg += '此证书的等级为 [%s] 级。\n' % holder.level
        msg += '您即将进行的签署,参数如下:\n'
        msg += ' 信任等级:[%s]\n 有效期:[%s] 天\n' % (trustlevel,signdays)
        msg += '\n现在需要您输入密码解密签署证书:\n [%s]' % signwith
        return pinreader(b,message=msg)
    
    try:
        signer.load_private_text (privatelist[signwith],_pinreader)
    except Exception,e:
        print "退出签署程序。密码错误或者用户手动取消。"
        log.warning('Sign process exited, either of a wrong passphrase, or had been cancelled manually.')
        exit()

    if signer.level <= holder.level:
        log.warning('Trying to sign a higher level certificate. User confirmation required.')
        if not _util.serious_confirm("您用于签署的证书(%d级)无权进行本操作,因为被签署的证书等级(%d级)不低于您。\n即使签署,该签名也是无效的。" % (signer.level,holder.level)):
            exit()
        log.info('User confirmed signing anyway.')

    signature = signer.sign_certificate(holder,trustlevel,signlife)

    savepath = os.path.join(_util.PATH_output,_util.uniqid() + '.sig')
    open(savepath,'w+').write(signature.encode('base64'))

    print '您的签名已经写入到:\n %s' % savepath
    log.info('Signature saved to [%s].',savepath)