def redact_token(unsafe):
    """
    redacts the GitHub authorization token if found in the unsafe input string

    :param:
        unsafe as str containing 'token TOKENVALUE' or 'https://TOKENVALUE'
    :return:
        safe as str; unsafe with the TOKENVALUE redacted; All except first and last three characters will remain on
        respective sides of -REDACTED-
    """

    safe = ''
    if 'https' in unsafe:
        strlist = unsafe.split()
        for item in strlist:
            if 'https' in item:
                url = item.split(':')
                redacted = url[0] + '://' + url[1][2:5] + "-REDACTED-" + url[1][-3:] + ':' + url[2]
                safe = safe + ' ' + redacted
            else:
                safe = safe + ' ' + item
    else:
        tokenfound = False
        strlist = unsafe.split()
        for item in strlist:
            if tokenfound:
                redacted = item[0:3] + "-REDACTED-" + item[-5:]
                safe = safe + ' ' + redacted
                tokenfound = False
            else:
                safe = safe + ' ' + item
                if 'token' in item:
                    tokenfound = True
    return safe