Exemplo n.º 1
0
def main():
    """
    MAIN
    """

    logger = bp_logger("EMAIL_VERIFIER")

    imap_server = imaputils.get_imapserv_conn()
    db_conn = dbutils.get_connection()

    query = """
            SELECT MAX(`verified_till`) FROM email_verification_logs
            """
    result = dbutils.db_select(db_conn, query)
    if result[0][0] == None:
        start = 0
    else:
        start = int(result[0][0])

    end = start

    msg, emails = imap_server.search(None, "SEEN")

    for email_id in emails[0].split():

        if email_id <= start:
            continue

        # TODO: Make this operation occur as batchwise processing
        if verify_email(imap_server, db_conn, email_id):
            logger.info("Everything seems alright.")
        else:
            logger.info("Marking {:d} as unread".format(int(email_id)))
            imap_server.store(int(email_id), "-FLAGS", "\SEEN")

        if int(email_id) > end:
            end = int(email_id)

    # Make an entry only if there was something to be checked.
    if end > start:

        query = """
                INSERT INTO email_verification_logs (verified_till, time)
                VALUES ({:d}, NOW())
                """.format(
            int(end)
        )

        dbutils.db_insert(db_conn, query)
Exemplo n.º 2
0
def main():
    """
    MAIN
    """

    logger = bp_logger('EMAIL_VERIFIER')

    imap_server = imaputils.get_imapserv_conn()
    db_conn = dbutils.get_connection()

    query = """
            SELECT MAX(`verified_till`) FROM email_verification_logs
            """
    result = dbutils.db_select(db_conn, query)
    if result[0][0] == None:
        start = 0
    else:
        start = int(result[0][0])

    end = start

    msg, emails = imap_server.search(None, "SEEN")

    for email_id in emails[0].split():

        if email_id <= start:
            continue

        # TODO: Make this operation occur as batchwise processing
        if verify_email(imap_server, db_conn, email_id):
            logger.info("Everything seems alright.")
        else:
            logger.info("Marking {:d} as unread".format(int(email_id)))
            imap_server.store(int(email_id), '-FLAGS', '\SEEN')

        if int(email_id) > end:
            end = int(email_id)

    # Make an entry only if there was something to be checked.
    if end > start:

        query = """
                INSERT INTO email_verification_logs (verified_till, time)
                VALUES ({:d}, NOW())
                """.format(int(end))

        dbutils.db_insert(db_conn, query)
Exemplo n.º 3
0
def main():
    """
    Main
    """

    logger = bp_logger("GET_EMAIL_ATTACHMENTS")

    config = ConfigParser()
    config.read(["../project_config"])

    imap_server = imaputils.get_imapserv_conn()

    connection = dbutils.get_connection()

    # This lists out the list of all the
    msg, emails = imap_server.search(None, "(UNSEEN)")
    # print emails

    # Go through each of the ids given out by IMAP
    for email_id in emails[0].split():

        attachments = imaputils.get_attachment(imap_server, email_id)

        for filename, content in attachments.items():

            # Filename has to match the required pattern.
            if re.search("run-[0-9]+-benchmark.log", filename) == None:
                logger.debug(
                    "The filename {:s} did not match the needed pattern. IMAP id : {:d}".format(filename, int(email_id))
                )
                continue

            filelocation = os.path.join(config.get("locations", "queue"), filename)

            md5 = hashlib.md5()
            md5.update(content)
            md5_hash = md5.hexdigest()
            filelocation = filelocation + "." + md5_hash

            #
            if util.check_if_file_exists_on_disk(filelocation):
                logger.debug("The file {:s} exists on the disk.".format(filelocation))
                continue
            else:
                file_queue = open(filelocation, "w")
                file_queue.write(content)
                logger.info("The file {:s} has been written to the disk.".format(filelocation))
                file_queue.close()

            # Add code to write it to the db
            query = """
                    INSERT INTO email_logs (`imap_id`, `md5`, `time`)
                    VALUES ({:d}, \"{:s}\", NOW())
                    """.format(
                int(email_id), md5_hash
            )

            hw_id = dbutils.db_insert(connection, query)

            if hw_id == None:
                logger.error("The query \n {:s} has not been inserted.".format(query))
def main():
    """
    Main
    """

    logger = bp_logger('GET_EMAIL_ATTACHMENTS')

    config = ConfigParser()
    config.read(['../project_config'])

    imap_server = imaputils.get_imapserv_conn()

    connection = dbutils.get_connection()

    # This lists out the list of all the
    msg, emails = imap_server.search(None, "(UNSEEN)")
    # print emails

    # Go through each of the ids given out by IMAP
    for email_id in emails[0].split():

        attachments = imaputils.get_attachment(imap_server, email_id)

        for filename, content in attachments.items():

            # Filename has to match the required pattern.
            if re.search("run-[0-9]+-benchmark.log", filename) == None:
                logger.debug(
                    "The filename {:s} did not match the needed pattern. IMAP id : {:d}"
                    .format(filename, int(email_id)))
                continue

            filelocation = os.path.join(config.get("locations", "queue"),
                                        filename)

            md5 = hashlib.md5()
            md5.update(content)
            md5_hash = md5.hexdigest()
            filelocation = filelocation + '.' + md5_hash

            #
            if util.check_if_file_exists_on_disk(filelocation):
                logger.debug(
                    "The file {:s} exists on the disk.".format(filelocation))
                continue
            else:
                file_queue = open(filelocation, 'w')
                file_queue.write(content)
                logger.info(
                    "The file {:s} has been written to the disk.".format(
                        filelocation))
                file_queue.close()

            # Add code to write it to the db
            query = """
                    INSERT INTO email_logs (`imap_id`, `md5`, `time`)
                    VALUES ({:d}, \"{:s}\", NOW())
                    """.format(int(email_id), md5_hash)

            hw_id = dbutils.db_insert(connection, query)

            if hw_id == None:
                logger.error(
                    "The query \n {:s} has not been inserted.".format(query))