#NEWLINE# def get_message( self , condition = None ) : #NEWLINE# #INDENT# message_ids = self . _get_all_message_ids ( ) #NEWLINE# if ( not message_ids ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if self . max_message_size : #NEWLINE# #INDENT# message_ids = self . _get_small_message_ids ( message_ids ) #NEWLINE# #UNINDENT# if self . archive : #NEWLINE# #INDENT# ( typ , folders ) = self . server . list ( pattern = self . archive ) #NEWLINE# if ( folders [ 0 ] is None ) : #NEWLINE# #INDENT# self . server . create ( self . archive ) #NEWLINE# #UNINDENT# #UNINDENT# for uid in message_ids : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( typ , msg_contents ) = self . server . uid ( 'fetch' , uid , '(RFC822)' ) #NEWLINE# if ( not msg_contents ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# message = self . get_email_from_bytes ( msg_contents [ 0 ] [ 1 ] ) #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( condition and ( not condition ( message ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# ( yield message ) #NEWLINE# #UNINDENT# except MessageParseError : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if self . archive : #NEWLINE# #INDENT# self . server . uid ( 'copy' , uid , self . archive ) #NEWLINE# #UNINDENT# self . server . uid ( 'store' , uid , '+FLAGS' , '(\\Deleted)' ) #NEWLINE# #UNINDENT# self . server . expunge ( ) #NEWLINE# return