#NEWLINE# def to_message( self ) : #NEWLINE# #INDENT# '\n        Returns raw email.Message instance.  Validates message first.\n        ' #NEWLINE# self . validate ( ) #NEWLINE# bodies = [ ( self . body , 'text/plain' ) , ( self . html , 'text/html' ) ] #NEWLINE# for ( idx , ( val , content_type ) ) in enumerate ( bodies ) : #NEWLINE# #INDENT# if ( val is None ) : #NEWLINE# #INDENT# bodies [ idx ] = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( base , Attachment ) : #NEWLINE# #INDENT# bodies [ idx ] = val . to_mailbase ( content_type ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# attachment = Attachment ( data = val , content_type = content_type , transfer_encoding = 'quoted-printable' , disposition = 'inline' ) #NEWLINE# bodies [ idx ] = attachment . to_mailbase ( content_type ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# ( body , html ) = bodies #NEWLINE# base = MailBase ( [ ( 'To' , ', ' . join ( self . recipients ) ) , ( 'From' , self . sender ) , ( 'Subject' , self . subject ) ] ) #NEWLINE# if self . cc : #NEWLINE# #INDENT# base [ 'Cc' ] = ', ' . join ( self . cc ) #NEWLINE# #UNINDENT# if self . extra_headers : #NEWLINE# #INDENT# base . update ( dict ( self . extra_headers ) ) #NEWLINE# #UNINDENT# if self . attachments : #NEWLINE# #INDENT# base . set_content_type ( 'multipart/mixed' ) #NEWLINE# altpart = MailBase ( ) #NEWLINE# base . attach_part ( altpart ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# altpart = base #NEWLINE# #UNINDENT# if ( body and html ) : #NEWLINE# #INDENT# altpart . set_content_type ( 'multipart/alternative' ) #NEWLINE# altpart . set_body ( None ) #NEWLINE# altpart . attach_part ( body ) #NEWLINE# altpart . attach_part ( html ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( body is not None ) : #NEWLINE# #INDENT# altpart . merge_part ( body ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( html is not None ) : #NEWLINE# #INDENT# altpart . merge_part ( html ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for attachment in self . attachments : #NEWLINE# #INDENT# attachment_mailbase = attachment . to_mailbase ( ) #NEWLINE# base . attach_part ( attachment_mailbase ) #NEWLINE# #UNINDENT# return to_message ( base )