#NEWLINE# def do_search( self , arg ) : #NEWLINE# #INDENT# 'Search mail.' #NEWLINE# usage = '\n' . join ( [ 'Usage: search [options]' , '' , 'Options:' , '    -a, --address=<address>     Search by address' , '    -d, --date=<date>           Search by date (YYYY-MM-DD)' , '    -s, --size=<SIZE>           Search by size (in bytes)' , '    -S, --subject=<subject>     Search by subject' , '    -t, --tags=<tags>           Searched tags (Comma separated)' , '    -T, --full-text=<text>      Searched tags (Comma separated)' , '    -h, --help                  Show help options.' ] ) #NEWLINE# try : #NEWLINE# #INDENT# args = docopt . docopt ( usage , argv = arg ) #NEWLINE# #UNINDENT# except SystemExit : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( args . get ( '--tags' ) is not None ) : #NEWLINE# #INDENT# args [ '--tags' ] = args [ '--tags' ] . split ( ',' ) #NEWLINE# #UNINDENT# if ( args [ '--date' ] is not None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# date = datetime . datetime . strptime ( args [ '--date' ] , '%Y-%m-%d' ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# date = None #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# date = None #NEWLINE# #UNINDENT# search_criterion = search . create_search_criterion ( address = args [ '--address' ] , date = date , subject = args [ '--subject' ] , size = args [ '--size' ] , tags = args [ '--tags' ] , text = args [ '--full-text' ] ) #NEWLINE# mail_set = search . fetch_uids ( self . imap_account , search_criterion = search_criterion ) #NEWLINE# if ( len ( mail_set ) == 0 ) : #NEWLINE# #INDENT# log . error ( 'No mail found' ) #NEWLINE# return 0 #NEWLINE# #UNINDENT# for mail_info in search . fetch_mails_info ( args . imap_account , mail_set = mail_set ) : #NEWLINE# #INDENT# sys . stdout . write ( 'UID : {:<10} From : {:<40.40} Subject : {:.50}\n' . format ( mail_info [ 'uid' ] , mail_info [ 'from' ] , mail_info [ 'subject' ] ) )