#NEWLINE# def extract_email( msg ) : #NEWLINE# #INDENT# 'Extract all the interesting fields from an email' #NEWLINE# msg_obj = extract_email_headers ( msg ) #NEWLINE# fpPos = msg . fp . tell ( ) #NEWLINE# msg . fp . seek ( 0 ) #NEWLINE# mail = email . message_from_string ( msg . fp . read ( ) ) #NEWLINE# contents = [ ] #NEWLINE# for part in mail . walk ( ) : #NEWLINE# #INDENT# if ( part . get_content_type ( ) == 'text/plain' ) : #NEWLINE# #INDENT# charset = part . get_content_charset ( ) #NEWLINE# if ( charset != None ) : #NEWLINE# #INDENT# payload = quopri . decodestring ( part . get_payload ( ) ) . decode ( charset ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# payload = quopri . decodestring ( part . get_payload ( ) ) . decode ( 'ascii' ) #NEWLINE# #UNINDENT# payload = format_plaintext_email ( payload ) #NEWLINE# contents . append ( payload ) #NEWLINE# #UNINDENT# #UNINDENT# content = '' . join ( contents ) #NEWLINE# msg_obj [ 'contents' ] = lxml . html . clean . clean_html ( content ) . encode ( 'utf-8' ) #NEWLINE# return msg_obj