Encodes a header value.

    Returns ASCII if possible, else returns an UTF-8 encoded e-mail header.

def _encodeHeader(headerValue):
    """
    Encodes a header value.

    Returns ASCII if possible, else returns an UTF-8 encoded e-mail header.
    """
    try:
        return headerValue.encode('ascii', 'strict')
    except UnicodeError:
        encoded = headerValue.encode("utf-8")
        return header.Header(encoded, "UTF-8").encode()