#NEWLINE# @ idiokit . stream #NEWLINE# def build_mail( self , events , to = [ ] , cc = [ ] , bcc = [ ] , template = '' , template_values = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , **keys ) : #NEWLINE# #INDENT# '\n        Return a mail object produced based on collected events and session parameters.\n        The "events" parameter is None when we just want to test building a mail.\n        ' #NEWLINE# if ( events is None ) : #NEWLINE# #INDENT# events = [ ] #NEWLINE# #UNINDENT# csv = templates . CSVFormatter ( ) #NEWLINE# template_keys = { #NEWLINE# #INDENT# 'csv' : csv , #NEWLINE# 'attach_csv' : templates . AttachUnicode ( csv ) , #NEWLINE# 'attach_and_embed_csv' : templates . AttachAndEmbedUnicode ( csv ) , #NEWLINE# 'attach_zip' : templates . AttachZip ( template ) , #NEWLINE# 'to' : templates . Const ( format_addresses ( to ) ) , #NEWLINE# 'cc' : templates . Const ( format_addresses ( cc ) ) , #NEWLINE# 'bcc' : templates . Const ( format_addresses ( bcc ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# for ( key , value ) in dict ( template_values ) . iteritems ( ) : #NEWLINE# #INDENT# template_keys [ key ] = templates . Event ( value ) #NEWLINE# #UNINDENT# mail_template = MailTemplate ( template , ** template_keys ) #NEWLINE# msg = ( yield idiokit . thread ( mail_template . format , events ) ) #NEWLINE# idiokit . stop ( msg )