Exemple #1
0
def encode_unstructured(name, value):
    if len(value) > MAX_HEADER_LENGTH:
        return to_utf8(value)
    try:
        return Header(value.encode("ascii"), "ascii",
                      header_name=name).encode(splitchars=' ;,')
    except (UnicodeEncodeError, UnicodeDecodeError):
        if is_address_header(name, value):
            return encode_address_header(name, value)
        else:
            return Header(to_utf8(value), "utf-8",
                          header_name=name).encode(splitchars=' ;,')
Exemple #2
0
def _encode_unstructured(name, value):
    try:
        return _email.encode_header(name, value.encode('ascii'), 'ascii')
    except (UnicodeEncodeError, UnicodeDecodeError):
        if _is_address_header(name, value):
            return _encode_address_header(name, value)

        return _email.encode_header(name, to_utf8(value), 'utf-8')
Exemple #3
0
def _encode_unstructured(name, value):
    try:
        return Header(
            value.encode("ascii"), "ascii",
            header_name=name).encode(splitchars=' ;,')
    except (UnicodeEncodeError, UnicodeDecodeError):
        if _is_address_header(name, value):
            return _encode_address_header(name, value)

        return Header(
            to_utf8(value), "utf-8",
            header_name=name).encode(splitchars=' ;,')