Exemple #1
0
def decode_header_field(field):
    """Decode and return given (header) `field`."""
    parts = decode_email_header(field)
    for idx, (text, charset) in enumerate(parts):
        # check this part, in case an error is raised
        parts[idx] = text.decode(charset or DEFAULT_CHARSET, errors="replace")
    return "".join(parts)
Exemple #2
0
def decode_header_field(field):
	"""Decode and return given (header) `field`."""
	parts = decode_email_header(field)
	for idx, (text, charset) in enumerate(parts):
		# check this part, in case an error is raised
		parts[idx] = text.decode(charset or DEFAULT_CHARSET, errors="replace")
	return "".join(parts)
Exemple #3
0
        def email_header_to_unicode(header_string):
            decoded_header = decode_email_header(header_string)
            default_charset = 'ASCII'

            text = ''.join([
                unicode(t[0], t[1] or default_charset) for t in decoded_header
            ])

            return text
Exemple #4
0
        def email_header_to_unicode(header_string, join_crlf=True):
            text = u''.join([
                txt.decode(enc) if enc else
                txt.decode('iso-8859-1') if isinstance(txt, bytes) else txt
                for (txt, enc) in decode_email_header(header_string)
            ])
            if join_crlf:
                text = u''.join(text.split(u'\r\n'))

            return text
Exemple #5
0
        def email_header_to_unicode(header_string, join_crlf=True):
            decoded_header = decode_email_header(header_string)
            default_charset = 'ASCII'

            text = ''.join([
                unicode(t[0], t[1] or default_charset) for t in decoded_header
            ])
            if join_crlf:
                text = u''.join(text.split('\r\n'))

            return text
Exemple #6
0
        def email_header_to_unicode(header_string):
            decoded_header = decode_email_header(header_string)
            default_charset = 'ASCII'

            text = ''.join(
                [
                    unicode(t[0], t[1] or default_charset) for t in
                    decoded_header
                ]
            )

            return text
Exemple #7
0
        def email_header_to_unicode(header_string, join_crlf=True):
            decoded_header = decode_email_header(header_string)
            default_charset = 'ASCII'

            text = ''.join(
                [
                    unicode(t[0], t[1] or default_charset) for t in
                    decoded_header
                ]
            )
            if join_crlf:
                text = u''.join(text.split('\r\n'))

            return text
Exemple #8
0
def decode_header_field_test(field):
	"""Decode and return given (header) `field`."""
	#print "before", field
	parts = decode_email_header(field)
	#print "parts", parts
	for idx, (text, charset) in enumerate(parts):
		# check this part, in case there is a charset problem!
		if charset:
			#print charset
			parts[idx] = text.decode(charset, errors="replace")
		else:
			#print "I am here"
			parts[idx] = text.decode(DEFAULT_CHARSET, errors="replace")
	#print "parts", parts
	data = "".join(parts)
	if type(data) != unicode:
		#print type(data)
		data = unicode(data, errors="ignore")
	#print "data now:", repr(data)
	return data
Exemple #9
0
def decode_header_field_test(field):
    """Decode and return given (header) `field`."""
    #print "before", field
    parts = decode_email_header(field)
    #print "parts", parts
    for idx, (text, charset) in enumerate(parts):
        # check this part, in case there is a charset problem!
        if charset:
            #print charset
            parts[idx] = text.decode(charset, errors="replace")
        else:
            #print "I am here"
            parts[idx] = text.decode(DEFAULT_CHARSET, errors="replace")
    #print "parts", parts
    data = "".join(parts)
    if type(data) != unicode:
        #print type(data)
        data = unicode(data, errors="ignore")
    #print "data now:", repr(data)
    return data