(fromAddress, recipients, debug)
return sources
Search for an address in a local sqlite database. Only email hashes are stored (sha256)
Search for an address in a local sqlite database. Only email hashes are stored (sha256)
Search for an address in a local sqlite database . Only email hashes are stored ( sha256 )
def searchInSQLite(fromAddress, recipients, debug):
    """Search for an address in a local sqlite database. Only email hashes are stored (sha256)"""
    sources = []

    try:

        import sqlite3
        import hashlib

        query = 'select source,abook from addresses where uid="{0}" and email_hash="{1}"'
        sqliteDatabase = configParser.get('sqlite', 'path')
        db = sqlite3.connect(sqliteDatabase)

        # Check if the email address is in the user's address book
        cursor = db.cursor()

        # get the from email address signature
        emailHash = hashlib.sha256(fromAddress).hexdigest()

        for rec in recipients:
            parts = parse_addr(rec[0])
            uid = parts[0]
            cursor.execute(query.format(uid, emailHash))

            # Store the address book sources when found
            for row in cursor:
                sources.append('{0}:{1}'.format(row[0], row[1]))

        if debug:
            GlobalLogQueue.put("Searched address hash {} for user {}: {} result(s)".format(
                emailHash, uid, len(sources)))

    # Make sure to not prevent the message to pass if something happen,
    # but log the error
    except Exception as error:
        GlobalLogQueue.put("Error when searching in address database: {}".format(error.message))

    # Cleanup: close the db connection if needed
    finally:
        if db:
            db.close()

    return sources
def searchInSQLite ( fromAddress , recipients , debug ) : sources = [ ] try : import sqlite3 import hashlib query = 'select source,abook from addresses where uid="{0}" and email_hash="{1}"' sqliteDatabase = configParser . get ( 'sqlite' , 'path' ) db = sqlite3 . connect ( sqliteDatabase ) # Check if the email address is in the user's address book cursor = db . cursor ( ) # get the from email address signature emailHash = hashlib . sha256 ( fromAddress ) . hexdigest ( ) for rec in recipients : parts = parse_addr ( rec [ 0 ] ) uid = parts [ 0 ] cursor . execute ( query . format ( uid , emailHash ) ) # Store the address book sources when found for row in cursor : sources . append ( '{0}:{1}' . format ( row [ 0 ] , row [ 1 ] ) ) if debug : GlobalLogQueue . put ( "Searched address hash {} for user {}: {} result(s)" . format ( emailHash , uid , len ( sources ) ) ) # Make sure to not prevent the message to pass if something happen, # but log the error except Exception as error : GlobalLogQueue . put ( "Error when searching in address database: {}" . format ( error . message ) ) # Cleanup: close the db connection if needed finally : if db : db . close ( ) return sources