def license_mapper(package_data, package):
    """
    Update package licensing and return package. Licensing structure for FreeBSD
    packages is a list of (non-scancode) license keys and a 'licenselogic' field.
    """
    license_logic, licenses = package_data.get('licenselogic'), package_data.get('licenses')

    if not licenses:
        return

    # licenselogic is found as 'or' in some cases in the wild
    if license_logic == 'or' or license_logic == 'dual':
        lics = [l.strip() for l in licenses if l and l.strip()]
        lics = ' OR '.join(lics)
    # licenselogic is found as 'and' in some cases in the wild
    elif license_logic == 'and' or license_logic == 'multi':
        lics = [l.strip() for l in licenses if l and l.strip()]
        lics = ' AND '.join(lics)
    # 'single' or default licenselogic value
    else:
        lics = [l.strip() for l in licenses if l and l.strip()]
        lics = ', '.join(lics)

    package.declared_license = lics or None
    return package