def user_match(user, username):
    """
    Return True if this is the user we are looking for.

    Compares a user structure from a Gerrit record to a username (or email
    address). All users match if the username is None.
    """
    if username is None:
        return True

    def field_match(field):
        if field not in user:
            return False
        return user[field] == username

    return field_match('email' if '@' in username else 'username')