def filter_encodings(encodings_raw, profiles_subsituted):
    """
    Filter down encodings list, adding unset names and excluding unused
    encodings.
    """
    # Give everything a name if not set
    for name, encoding in encodings_raw.items():
        if not 'name' in encoding:
            encoding['name'] = name

    # Strip out un-used code pages
    unused = encodings_raw.keys()
    for profile in profiles_subsituted.values():
        used = profile['codePages'].values()
        unused = [x for x in unused if x not in used]
    return {k: v for k, v in encodings_raw.items() if k not in unused}