Beispiel #1
0
def getActiveMailContent(mail):
    content = u""
    try:
        if mail.is_multipart():
            content = u""
            raise TypeError, u"The active is edit by human"
        else:
            contenttype = mail.get_content_charset()
            contentencoding = email.Header.decode_header(mail['Content-Transfer-Encoding'])[0][0]
            contentencoding = xstring.str2unicode(contentencoding)
            payload = mail.get_payload(decode = contentencoding)
            if contenttype==None:
                content = xstring.str2unicode(payload) 
            else:
                try:
                    content = unicode(payload,contenttype)
                except UnicodeDecodeError:
                    content = u""
                    raise TypeError, u"The content type error"
    except:
        traceStr = traceback.format_exc()
        logging.error(traceStr)
        content = u""
    return content
Beispiel #2
0
def requestActive(key):
    try:
        emailaddr = g_emailaddr
        emailpwd = g_emailpwd
        thistime = datetime.datetime.now()
        sender =  emailaddr
        receiver = emailaddr
        subject = xstring.str2unicode(str(thistime)) + u"[" + xstring.str2unicode(SysInfo.getHostName()) + u"]"
        smtpserver = g_smtpserver
        username = emailaddr
        password = emailpwd

        emailcontent = key
        emailcontent += u"\r\n\r\n"
        emailcontent = emailcontent + u"\r\n" \
                       + u"time£º" + xstring.str2unicode(str(thistime)) + u"\r\n" \
                       + u"hostname£º" + xstring.str2unicode(SysInfo.getHostName()) + u"\r\n" \
                       + u"platform£º" + xstring.str2unicode(SysInfo.getPlatform()) + u"\r\n" \
                       + u"mac£º" + xstring.str2unicode(SysInfo.getEnableMacs()) + u"\r\n" \
                       + u"cpu£º" + xstring.str2unicode(SysInfo.getCpuInfo()) + u"\r\n" \
                       + u"mem£º" + xstring.str2unicode(SysInfo.getMemInfo()) + u"\r\n" \
                       + u"disk£º" + xstring.str2unicode(SysInfo.getDiskInfo()) + u"\r\n" \

        msg = MIMEText(emailcontent,'plain','utf-8')
        msg['Subject'] = Header(subject, 'utf-8')
        msg['From'] = sender
        msg['To'] = receiver
         
        smtp = smtplib.SMTP() 
        smtp.connect(g_smtpserver) 
        smtp.login(username, password) 
        smtp.sendmail(sender, receiver, msg.as_string()) 
        smtp.quit()
    except:
        traceStr = traceback.format_exc()
        logging.error(traceStr)
Beispiel #3
0
def getActiveValue(key, softname):
    value = None
    try:
        host = g_popserver  
        username = g_emailaddr 
        password = g_emailpwd 
          
        pop_conn = poplib.POP3(host)   
        pop_conn.user(username)   
        pop_conn.pass_(password)   

        mailCount,size = pop_conn.stat()
        realsubject = u"[" + softname + u"-active" +u"]"
        #Get messages from server:
        activemail = None
        for i in range(mailCount, 0, -1):
            msg = pop_conn.retr(i)
            msgstr = '\n'.join(msg[1])
            mail = email.message_from_string(msgstr)
            subject = email.Header.decode_header(mail['subject'])[0][0]
            if xstring.str2unicode(subject) == realsubject:
                activemail = mail
                break
        pop_conn.quit()

        if activemail != None:
            content = getActiveMailContent(activemail)
            items = content.split(u"\n")
            dic = {}
            for item in items:
                if item!=u"":
                    if item[-1] == u"\r":
                        item = item[0:-1]
                    keyvalue = item.split(u"===>")
                    if len(keyvalue) == 2:
                        dic[keyvalue[0]] = keyvalue[1]
            value = dic[key]       
    except:
        value = None
        traceStr = traceback.format_exc()
        logging.error(traceStr)
    return value