@@ -0,0 +1,2452 @@
+#! /usr/bin/env python%0A# -*- coding: utf-8 -*-%0A%0A%0A%22%22%22Use IMAP CLI to search trhough every mailbox on an account.%22%22%22%0A%0A%0Aimport argparse%0Aimport getpass%0Aimport logging%0Aimport os%0Aimport sys%0A%0Aimport imap_cli%0Afrom imap_cli import search%0A%0A%0Aapp_name = os.path.splitext(os.path.basename(__file__))%5B0%5D%0Alog = logging.getLogger(app_name)%0A%0A%0Adef truncate_string(string, length):%0A    minus_than_position = string.find('%3C')%0A    if minus_than_position %3E 0 and string.find('%3E') %3E minus_than_position:%0A        string = string%5B0:minus_than_position%5D%0A    return string if len(string) %3C length else u'%7B0%7D%E2%80%A6'.format(string%5B0:length%5D)%0A%0A%0Adef main():%0A    parser = argparse.ArgumentParser(description=__doc__)%0A    parser.add_argument('imap_server', help=%22IMAP Server hostname%22)%0A    parser.add_argument('searched_address', help=%22Searched address%22)%0A    parser.add_argument('-l', '--login', help=%22Login for IMAP account%22)%0A    parser.add_argument('--no-ssl', action='store_true', help=%22Don't use SSL%22)%0A    parser.add_argument('-v', '--verbose', action='store_true', help='increase output verbosity')%0A%0A    args = parser.parse_args()%0A    password = getpass.getpass()%0A%0A    logging.basicConfig(level=logging.INFO, stream=sys.stdout)%0A%0A    try:%0A        imap_account = imap_cli.connect(%0A            hostname=args.imap_server,%0A            username=args.login,%0A            password=password,%0A            ssl=not args.no_ssl,%0A        )%0A        for directory_status in sorted(imap_cli.status(imap_account), key=lambda obj: obj%5B'directory'%5D):%0A            imap_cli.change_dir(imap_account, directory_status%5B'directory'%5D)%0A%0A            mail_set = search.fetch_uids(%0A                imap_account,%0A                search_criterion=%5Bsearch.create_search_criterion_by_mail_address(args.searched_address)%5D,%0A            )%0A%0A            if len(mail_set) %3E 0:%0A                sys.stdout.write(u'%7B%7D Directory%5Cn'.format(directory_status%5B'directory'%5D))%0A%0A                for mail_info in search.fetch_mails_info(imap_account, mail_set=mail_set):%0A                    sys.stdout.write(u'    %7B:%3C10%7D From : %7B:%3C30%7D %5CtSubject : %7B%7D%5Cn'.format(%0A                        mail_info%5B'uid'%5D,%0A                        truncate_string(mail_info%5B'from'%5D, 30),%0A                        truncate_string(mail_info%5B'subject'%5D, 50),%0A                    ))%0A        imap_cli.disconnect(imap_account)%0A    except KeyboardInterrupt:%0A        log.info('Interrupt by user, exiting')%0A%0A    return 0%0A%0Aif __name__ == %22__main__%22:%0A    sys.exit(main())%0A

Add an example script to search through every mailbox