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)
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
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
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
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
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
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