#NEWLINE# def __UidFetch( self , search_criterion , fetch_parts , max_fetch = ( - 1 ) ) : #NEWLINE# #INDENT# logging . info ( 'Fetching message infos' ) #NEWLINE# logging . info ( '  Fetching message list' ) #NEWLINE# data = self . __UidCommand ( 'SEARCH' , search_criterion ) #NEWLINE# message_ids = data [ 0 ] . split ( ) #NEWLINE# logging . info ( ( '  %d messages were listed' % len ( message_ids ) ) ) #NEWLINE# if ( ( max_fetch != ( - 1 ) ) and ( len ( message_ids ) > max_fetch ) ) : #NEWLINE# #INDENT# if self . __random_subset : #NEWLINE# #INDENT# random . seed ( len ( message_ids ) ) #NEWLINE# subset_size = ( max_fetch * 30 ) #NEWLINE# if ( len ( message_ids ) > subset_size ) : #NEWLINE# #INDENT# message_ids = message_ids [ ( ( - subset_size ) - 1 ) : ( - 1 ) ] #NEWLINE# #UNINDENT# message_ids = random . sample ( message_ids , max_fetch ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# message_ids = message_ids [ ( ( - max_fetch ) - 1 ) : ( - 1 ) ] #NEWLINE# #UNINDENT# #UNINDENT# message_infos = [ ] #NEWLINE# chunk_size = ( ( ( fetch_parts . find ( 'HEADER' ) != ( - 1 ) ) and 1000 ) or 100000 ) #NEWLINE# for i in xrange ( 0 , len ( message_ids ) , chunk_size ) : #NEWLINE# #INDENT# chunk_start = i #NEWLINE# chunk_end = ( i + chunk_size ) #NEWLINE# if ( fetch_parts > len ( message_ids ) ) : #NEWLINE# #INDENT# chunk_end = len ( message_ids ) #NEWLINE# #UNINDENT# chunk_message_ids = message_ids [ chunk_start : chunk_end ] #NEWLINE# logging . info ( '  Fetching info for %d messages (%d/%d)' , len ( chunk_message_ids ) , chunk_end , len ( message_ids ) ) #NEWLINE# fetch_reply = self . __UidCommand ( 'FETCH' , ',' . join ( chunk_message_ids ) , fetch_parts ) #NEWLINE# logging . info ( '  Parsing replies' ) #NEWLINE# message_infos . extend ( self . __ParseFetchReply ( fetch_reply ) ) #NEWLINE# #UNINDENT# logging . info ( ( '  Got %d message infos' % len ( message_infos ) ) ) #NEWLINE# return message_infos