Ejemplo n.º 1
0
def parseEmail(emailFile):

    escon = es.ESload()

    start = time.time()

    f = open(emailFile, 'r')
    msg = email.message_from_file(f)
    f.close()

    env = open(emailFile + '.envelope', 'r')
    envelope = env.readline()
    env.close()
    
    metaData = getMetaData(msg)
    
    try:  
        if msg.is_multipart():
            data = mimeEmail(msg, envelope, metaData, )
        else:
            data = rawEmail(msg, envelope, metaData)
        
    except NoBoundaryInMultipartDefect:
        data = rawEmail(msg, envelope, metaData, )
    
    key = createKey(metaData[0], envelope)
    envData = elasticEnvelope(envelope)

    #write data into ES
    escon.indexEmailData(data, key)
    escon.indexEnvelopeData(envData, key)
     
    duration = time.time() - start 
   
    return duration
Ejemplo n.º 2
0
def checkData(emailFile):
    
    logger = insertData.get_logger()
    logger.info("Reading email %s" % emailFile)
    logger.info("Task id %s" %  checkData.request.id)

    env = open(emailFile + '.envelope', 'r')
    envelope = env.readline()
    env.close()

    f = open(emailFile, 'r')
    msg = message_from_file(f)
    metaData = getMetaData(msg)
    key = createKey(metaData[0], envelope)
    f.close()

    email = rawEmail(key)
    #print email
    print key
    if email != 0: 

        f = open(emailFile, 'r')
        sEmail = f.readlines()
        f.close()

        m = hashlib.sha1()
        m.update(''.join(sEmail))
        sHash = m.hexdigest()

        m = hashlib.sha1()
        m.update(email)
        dHash = m.hexdigest()
 
        if sHash != dHash:
            logger.info("[Error/EmailTest] Email corrupted.] < %s >" % emailFile)
            #return "0"
        else:
            logger.info("[Email data test: OK]")