def check_required_files(file_map, file_names):
    """ Given a file_map for the assignment, the names of all
    attachments taken from the current email in file_names, and a
    logger, this function checks that each file marked mandatory was
    extracted from an attachment. 

    Returns (missing_required_files, all_mandatory_files_present),
    where missing_required_files is a list of names of missing
    required files and all_mandatory_files_present is a boolean."""

    all_mandatory_files_present = True
    missing_required_files=[]

    # Loop over all filenames known for this assignment.
    for assignment_file_name in file_map.keys():
        (ftype, fpriority) = file_map[assignment_file_name]

        # File is mandatory but was not attached.
        if ((ftype == 'mandatory') and (assignment_file_name not in file_names)):
                all_mandatory_files_present = False
                missing_required_files.append(assignment_file_name)

    return (all_mandatory_files_present, missing_required_files)