def do_search(self, arg):
        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.',
        ])
        try:
            args = docopt.docopt(usage, argv=arg)
        except SystemExit:
            return

        if args.get('--tags') is not None:
            args['--tags'] = args['--tags'].split(',')
        if args['--date'] is not None:
            try:
                date = datetime.datetime.strptime(args['--date'], '%Y-%m-%d')
            except ValueError:
                date = None
        else:
            date = None

        search_criterion = search.create_search_criterion(
            address=args['--address'],
            date=date,
            subject=args['--subject'],
            size=args['--size'],
            tags=args['--tags'],
            text=args['--full-text'],
        )
        mail_set = search.fetch_uids(self.imap_account,
                                     search_criterion=search_criterion)
        if len(mail_set) == 0:
            log.error('No mail found')
            return 0
        for mail_info in search.fetch_mails_info(self.imap_account,
                                                 mail_set=mail_set):
            sys.stdout.write(
                u'UID : {:<10} From : {:<40.40} Subject : {:.50}\n'.format(
                    mail_info['uid'],
                    mail_info['from'],
                    mail_info['subject']))
Search mail.
dataset/ETHPy150Open Gentux/imap-cli/imap_cli/scripts/imap_shell.py/ImapShell.do_search