def main(): args = docopt.docopt('\n'.join(__doc__.split('\n')[2:]), version=const.VERSION) logging.basicConfig( level=logging.DEBUG if args['--verbose'] else logging.INFO, stream=sys.stdout, ) try: connect_conf = config.new_context_from_file(args['--config-file'], section='imap') if connect_conf is None: return 1 display_conf = config.new_context_from_file(args['--config-file'], section='display') if args['--format'] is not None: display_conf['format_status'] = six.text_type(args['--format']) imap_account = imap_cli.connect(**connect_conf) for directory_status in sorted(imap_cli.status(imap_account), key=lambda obj: obj['directory']): sys.stdout.write( display_conf['format_status'].format(**directory_status)) sys.stdout.write('\n') except KeyboardInterrupt: log.info('Interrupt by user, exiting') return 0
def test_status_with_wrong_imap_call(self): # TODO(rsoufflet) This test doesn't seem to be pass self.imap_account = imaplib.IMAP4_SSL() self.imap_account.fail = True for directory_status in imap_cli.status(self.imap_account): assert directory_status == {'directory': u'Δiπectòrÿ_ñämé', 'unseen': "0", 'count': "1", 'recent': "1"}
def do_status(self, arg): 'Print status of all IMAP folder in this account' directory_statuses = sorted(imap_cli.status(self.imap_account), key=lambda obj: obj['directory']) for directory_status in directory_statuses: sys.stdout.write( u'{:<30} : Unseen {:<6} Recent {:<6} Total {:<6}\n'.format( directory_status['directory'], directory_status['unseen'], directory_status['recent'], directory_status['count']))
def test_status(self): self.imap_account = imaplib.IMAP4_SSL() statuses = list(imap_cli.status(self.imap_account)) for directory_status in statuses: assert directory_status == {'directory': u'Δiπectòrÿ_ñämé', 'unseen': "0", 'count': "1", 'recent': "1"} assert len(statuses) == 2
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('imap_server', help="IMAP Server hostname") parser.add_argument('searched_address', help="Searched address") parser.add_argument('-l', '--login', help="Login for IMAP account") parser.add_argument('--no-ssl', action='store_true', help="Don't use SSL") parser.add_argument('-v', '--verbose', action='store_true', help='increase output verbosity') args = parser.parse_args() password = getpass.getpass() logging.basicConfig(level=logging.INFO, stream=sys.stdout) try: imap_account = imap_cli.connect( hostname=args.imap_server, username=args.login, password=password, ssl=not args.no_ssl, ) for directory_status in sorted(imap_cli.status(imap_account), key=lambda obj: obj['directory']): imap_cli.change_dir(imap_account, directory_status['directory']) mail_set = search.fetch_uids( imap_account, search_criterion=[ search.create_search_criterion_by_mail_address( args.searched_address) ], ) if len(mail_set) > 0: sys.stdout.write(u'{} Directory\n'.format( directory_status['directory'])) for mail_info in search.fetch_mails_info(imap_account, mail_set=mail_set): format_string = u''.join([ u' {:<10} ', u'From : {:<30.30} \t', u'Subject : {:.50}\n' ]) sys.stdout.write( format_string.format(mail_info['uid'], mail_info['from'], mail_info['subject'])) imap_cli.disconnect(imap_account) except KeyboardInterrupt: log.info('Interrupt by user, exiting') return 0
def test_status_with_wrong_imap_call(self): # TODO(rsoufflet) This test doesn't seem to be pass self.imap_account = imaplib.IMAP4_SSL() self.imap_account.fail = True for directory_status in imap_cli.status(self.imap_account): assert directory_status == { 'directory': u'Δiπectòrÿ_ñämé', 'unseen': "0", 'count': "1", 'recent': "1" }
def test_status(self): self.imap_account = imaplib.IMAP4_SSL() statuses = list(imap_cli.status(self.imap_account)) for directory_status in statuses: assert directory_status == { 'directory': u'Δiπectòrÿ_ñämé', 'unseen': "0", 'count': "1", 'recent': "1" } assert len(statuses) == 2
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('imap_server', help="IMAP Server hostname") parser.add_argument('searched_address', help="Searched address") parser.add_argument('-l', '--login', help="Login for IMAP account") parser.add_argument('--no-ssl', action='store_true', help="Don't use SSL") parser.add_argument('-v', '--verbose', action='store_true', help='increase output verbosity') args = parser.parse_args() password = getpass.getpass() logging.basicConfig(level=logging.INFO, stream=sys.stdout) try: imap_account = imap_cli.connect( hostname=args.imap_server, username=args.login, password=password, ssl=not args.no_ssl, ) for directory_status in sorted(imap_cli.status(imap_account), key=lambda obj: obj['directory']): imap_cli.change_dir(imap_account, directory_status['directory']) mail_set = search.fetch_uids( imap_account, search_criterion=[ search.create_search_criterion_by_mail_address( args.searched_address)], ) if len(mail_set) > 0: sys.stdout.write(u'{} Directory\n'.format( directory_status['directory'])) for mail_info in search.fetch_mails_info(imap_account, mail_set=mail_set): format_string = u''.join([ u' {:<10} ', u'From : {:<30.30} \t', u'Subject : {:.50}\n']) sys.stdout.write(format_string.format( mail_info['uid'], mail_info['from'], mail_info['subject'])) imap_cli.disconnect(imap_account) except KeyboardInterrupt: log.info('Interrupt by user, exiting') return 0
def status(): reset_buffer('vimap-status') b = vim.current.buffer b[:] = None ensure_connection() for directory_status in sorted(imap_cli.status(imap_account), key=lambda obj: obj['directory']): b.append(display_conf['format_status'].format(**directory_status)) b[0] = u'Mailbox list:' for key, action in status_mappings: vim.command("nnoremap <silent> <buffer> {} {}".format(key, action))
def main(): args = docopt.docopt('\n'.join(usage.split('\n'))) logging.basicConfig( level=logging.DEBUG if args['--verbose'] else logging.WARNING, stream=sys.stdout, ) pynotify.init(app_name) connection_config = config.new_context_from_file(args['--config-file'], section='imap') if connection_config is None: return 1 try: delay = int(args['--delay'] or 60) except ValueError: log.error('Wrong value for options "delay"') return 1 format_str = args['--format'] or u' '.join([ u'{recent:<3} new mails in ', u'{directory} ({count} total)']) imap_account = imap_cli.connect(**connection_config) time_count = 0 sys.stdout.write('\n') while True: time_count += 1 if time_count % delay == 0: notifications = [] for status in imap_cli.status(imap_account): if (status['directory'] in args['<directories>'] and status['recent'] != '0'): notifications.append(format_str.format(**status)) if len(notifications) > 0: notifier = pynotify.Notification("IMAP Notify", u'\n'.join(notifications)) notifier.show() time.sleep(1) return 0
def main(): args = docopt.docopt('\n'.join(usage.split('\n'))) logging.basicConfig( level=logging.DEBUG if args['--verbose'] else logging.WARNING, stream=sys.stdout, ) pynotify.init(app_name) connection_config = config.new_context_from_file(args['--config-file'], section='imap') if connection_config is None: return 1 try: delay = int(args['--delay'] or 60) except ValueError: log.error('Wrong value for options "delay"') return 1 format_str = args['--format'] or u' '.join( [u'{recent:<3} new mails in ', u'{directory} ({count} total)']) imap_account = imap_cli.connect(**connection_config) time_count = 0 sys.stdout.write('\n') while True: time_count += 1 if time_count % delay == 0: notifications = [] for status in imap_cli.status(imap_account): if (status['directory'] in args['<directories>'] and status['recent'] != '0'): notifications.append(format_str.format(**status)) if len(notifications) > 0: notifier = pynotify.Notification("IMAP Notify", u'\n'.join(notifications)) notifier.show() time.sleep(1) return 0
def status_controller(req): return json.dumps(sorted(imap_cli.status(imap_account), key=lambda obj: obj["directory"]), indent=2)
def status_controller(req): return json.dumps(sorted(imap_cli.status(imap_account), key=lambda obj: obj['directory']), indent=2)