def correct_encoding(encoding):
    """Correct encoding

    UTF-8 uses an optional BOM (0xef, 0xbb, 0xbf). We always want to use that
    because it prevents errors. The codepage to use would then be UTF-8-SIG
    instead of UTF-8. However, UTF-8-SIG is an ugly name, so we just use UTF-8
    as name and correct it where required.

    Arguments:
        encoding    codepage string to be checked

    Return:
        corrected codepage as string
    """
    in_encoding = str(encoding)
    out_encoding = in_encoding

    in_encoding = in_encoding.upper().replace("-", "")
    if in_encoding.startswith("UTF8"):
        # always use UTF-8-SIG instead of UTF-8
        out_encoding = "utf-8-sig"

    return out_encoding