help with unicode email parse

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • neoedmund

    #1

    help with unicode email parse

    i want to get the subject from email and construct a filename with the
    subject.
    but tried a lot, always got error like this:
    UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xe9 in position 4:
    ordinal not in range(128)


    msg = email.message_f rom_string( text )
    title = decode_header( msg["Subject"] )
    title= title[0][0]
    #title=title.en code("utf8")
    print title
    fn = ""+path+"/"+stamp+"-"+title+".m ail"


    the variable "text" come from sth like this:
    ( header, msg, octets ) = a.retr( i )
    text= list2txt( msg )
    def list2txt( l ):
    return reduce( lambda x, y:x+"\r\n"+y, l )

    anyone can help me out? thanks.

  • Diez B. Roggisch

    #2
    Re: help with unicode email parse

    neoedmund schrieb:
    i want to get the subject from email and construct a filename with the
    subject.
    but tried a lot, always got error like this:
    UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xe9 in position 4:
    ordinal not in range(128)
    >
    >
    msg = email.message_f rom_string( text )
    title = decode_header( msg["Subject"] )
    title= title[0][0]
    #title=title.en code("utf8")
    print title
    fn = ""+path+"/"+stamp+"-"+title+".m ail"
    >
    >
    the variable "text" come from sth like this:
    ( header, msg, octets ) = a.retr( i )
    text= list2txt( msg )
    def list2txt( l ):
    return reduce( lambda x, y:x+"\r\n"+y, l )
    >
    anyone can help me out? thanks.
    Where does the exception occur?

    Diez

    Comment

    Working...