(fromAddress, recipients, debug, dbConnection)
return sources
Search for an address in the RoundCube database.
Search for an address in the RoundCube database.
Search for an address in the RoundCube database .
def searchInRoundCube(fromAddress, recipients, debug, dbConnection):
    """Search for an address in the RoundCube 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 cg.name from contacts as c"
                       " left join contactgroupmembers as cgm"
                       " on cgm.contact_id = c.contact_id"
                       " left join contactgroups as cg"
                       " on cg.contactgroup_id=cgm.contactgroup_id"
                       " left join users as u"
                       " on u.user_id = c.user_id"
                       " where u.username='{}' and "
                       " c.words like '%{}%' and"
                       " c.del = 0"
                       .format(uid, fromAddress))

            tablesCursor.execute(abQuery)

            abooks = tablesCursor.fetchall()

            # End to search in this recipient
            tablesCursor.close()

            # Store the address book name, or "default" when no name
            for abResult in abooks:
                # Get the first cell as a result
                abName = abResult[0]

                if abName:
                    source = "Roundcube:{}".format(abName)
                else:
                    source = "Roundcube:default"

                # Insert if not already inside.
                if not source in sources:
                    sources.append(source)

        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 searchInRoundCube ( 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 cg.name from contacts as c" " left join contactgroupmembers as cgm" " on cgm.contact_id = c.contact_id" " left join contactgroups as cg" " on cg.contactgroup_id=cgm.contactgroup_id" " left join users as u" " on u.user_id = c.user_id" " where u.username='{}' and " " c.words like '%{}%' and" " c.del = 0" . format ( uid , fromAddress ) ) tablesCursor . execute ( abQuery ) abooks = tablesCursor . fetchall ( ) # End to search in this recipient tablesCursor . close ( ) # Store the address book name, or "default" when no name for abResult in abooks : # Get the first cell as a result abName = abResult [ 0 ] if abName : source = "Roundcube:{}" . format ( abName ) else : source = "Roundcube:default" # Insert if not already inside. if not source in sources : sources . append ( source ) 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