import re


def normalize_archives_url(url):
    """
    Normalize url.

    will try to infer, find or guess the most useful archives URL, given a URL.

    Return normalized URL, or the original URL if no improvement is found.
    """
    # change new IETF mailarchive URLs to older, still available text .mail archives
    new_ietf_exp = re.compile(
        "https://mailarchive\\.ietf\\.org/arch/search/"
        "\\?email_list=(?P<list_name>[\\w-]+)"
    )
    ietf_text_archives = (
        r"https://www.ietf.org/mail-archive/text/\g<list_name>/"
    )
    new_ietf_browse_exp = re.compile(
        r"https://mailarchive.ietf.org/arch/browse/(?P<list_name>[\w-]+)/?"
    )

    match = new_ietf_exp.match(url)
    if match:
        return re.sub(new_ietf_exp, ietf_text_archives, url)

    match = new_ietf_browse_exp.match(url)
    if match:
        return re.sub(new_ietf_browse_exp, ietf_text_archives, url)

    return url