def is_email_logged(db_conn, email_id): """ Check if the file has been logged into the db. """ query = """ SELECT * from email_logs where imap_id = {:d} """.format(int(email_id)) result = dbutils.db_select(db_conn, query) if len(result) == 0: return False else: return True
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)
def is_email_logged(db_conn, email_id): """ Check if the file has been logged into the db. """ query = """ SELECT * from email_logs where imap_id = {:d} """.format( int(email_id) ) result = dbutils.db_select(db_conn, query) if len(result) == 0: return False else: return True
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)