(fromAddress, recipients, debug, dbConnection)
return sources
Search for an address in the SOGo database.
Search for an address in the SOGo database.
Search for an address in the SOGo database .
def searchInSOGo(fromAddress, recipients, debug, dbConnection):
    """Search for an address in the SOGo database."""

    try:
        # Nothing found
        if not dbConnection:
            GlobalLogQueue.put("Could not connect to the database")
            return []

        sources = []

        for rec in recipients:
            parts = parse_addr(rec[0])
            uid = parts[0]

            # First, get all the address books from this user
            tablesCursor = dbConnection.cursor()
            abQuery = ("select c_foldername, regexp_replace(c_location, '.*/sogo', 'sogo')"
                       " from sogo_folder_info where"
                       " c_folder_type='Contact' and c_location like '%sogo{}%';".format(uid))

            tablesCursor.execute(abQuery)

            tables = tablesCursor.fetchall()

            # End to search in this address book
            tablesCursor.close()

            # For each table, run a query to check if the address is inside
            for tableInfo in tables:
                abName = tableInfo[0]
                tableName = tableInfo[1]
                cursor = dbConnection.cursor()
                countQuery = "select count(*) from {} where c_content LIKE '%EMAIL%:{}%';".format(tableName, fromAddress)
                if debug:
                    GlobalLogQueue.put("Searching in table {} ({})".format(tableName, abName))
                cursor.execute(countQuery)
                result = cursor.fetchone()
                cursor.close()

                # Store the address book sources when found
                if int(result[0]) > 0:
                    sources.append('SOGo:{}'.format(abName))

        if debug:
            GlobalLogQueue.put("Searched address {} for user {}: {} result(s)".format(
                fromAddress, 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))

    return sources
def searchInSOGo ( fromAddress , recipients , debug , dbConnection ) : try : # Nothing found if not dbConnection : GlobalLogQueue . put ( "Could not connect to the database" ) return [ ] sources = [ ] for rec in recipients : parts = parse_addr ( rec [ 0 ] ) uid = parts [ 0 ] # First, get all the address books from this user tablesCursor = dbConnection . cursor ( ) abQuery = ( "select c_foldername, regexp_replace(c_location, '.*/sogo', 'sogo')" " from sogo_folder_info where" " c_folder_type='Contact' and c_location like '%sogo{}%';" . format ( uid ) ) tablesCursor . execute ( abQuery ) tables = tablesCursor . fetchall ( ) # End to search in this address book tablesCursor . close ( ) # For each table, run a query to check if the address is inside for tableInfo in tables : abName = tableInfo [ 0 ] tableName = tableInfo [ 1 ] cursor = dbConnection . cursor ( ) countQuery = "select count(*) from {} where c_content LIKE '%EMAIL%:{}%';" . format ( tableName , fromAddress ) if debug : GlobalLogQueue . put ( "Searching in table {} ({})" . format ( tableName , abName ) ) cursor . execute ( countQuery ) result = cursor . fetchone ( ) cursor . close ( ) # Store the address book sources when found if int ( result [ 0 ] ) > 0 : sources . append ( 'SOGo:{}' . format ( abName ) ) if debug : GlobalLogQueue . put ( "Searched address {} for user {}: {} result(s)" . format ( fromAddress , 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 ) ) return sources