def header_unquote(val):
    """ removes the quotes from a header value """
    if val[0] == val[-1] == '"':
        val = val[1:-1]
        if val[1:3] == ':\\' or val[:2] == '\\\\':
            val = val.split('\\')[-1]
        return val.replace('\\\\', '\\').replace('\\"', '"')
    return val
