#NEWLINE# @ idiokit . stream #NEWLINE# def fetch_mails( self , filter ) : #NEWLINE# #INDENT# ( result , data ) = ( yield self . call ( 'uid' , 'SEARCH' , None , filter ) ) #NEWLINE# if ( ( not data ) or ( not data [ 0 ] ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# for uid in data [ 0 ] . split ( ) : #NEWLINE# #INDENT# collected = [ ] #NEWLINE# ( yield ( self . walk_mail ( uid ) | idiokit . map ( collected . append ) ) ) #NEWLINE# parts = list ( ) #NEWLINE# for ( path , headers ) in collected : #NEWLINE# #INDENT# parts . append ( ( headers , self . fetcher ( uid , path ) ) ) #NEWLINE# #UNINDENT# if parts : #NEWLINE# #INDENT# top_header = parts [ 0 ] [ 0 ] [ 0 ] #NEWLINE# subject = get_header ( top_header , 'Subject' , '<no subject>' ) #NEWLINE# sender = get_header ( top_header , 'From' , '<unknown sender>' ) #NEWLINE# self . log . info ( 'Handling mail {0!r} from {1!r}' . format ( subject , sender ) ) #NEWLINE# ( yield self . handle ( parts ) ) #NEWLINE# self . log . info ( 'Done with mail {0!r} from {1!r}' . format ( subject , sender ) ) #NEWLINE# #UNINDENT# ( yield self . call ( 'uid' , 'STORE' , uid , '+FLAGS' , '(\\Seen)' ) )