def main(): if sys.version_info < (3, 6): sys.exit("Python 3.6 or later is required.") args = parser.parse_args() no_actions = len(filter(None, (args.tag, args.watch, args.move_mails))) if no_actions == 0: sys.exit('You need to specify an action') elif no_actions > 1: sys.exit('Please specify exactly one action') no_query_modifiers = len(filter(None, (args.all, args.new, args.query))) if no_query_modifiers == 0 and not args.watch \ and not args.move_mails: sys.exit('You need to specify one of --new, --all or a query string') elif no_query_modifiers > 1: sys.exit('Please specify either --all, --new or a query string') read_notmuch_settings(args.notmuch_config) if args.new: query_string = get_notmuch_new_query() elif args.all: query_string = '' else: query_string = ' '.join(args.query) loglevel = { 0: logging.WARNING, 1: logging.INFO, 2: logging.DEBUG, }[min(2, args.verbosity)] logging.basicConfig(level=loglevel) sys.path.insert(0, user_config_dir) for file_name in glob.glob1(user_config_dir, '*.py'): logging.info('Importing user filter %r' % (file_name, )) __import__(file_name[:-3], level=0) if args.move_mails: args.mail_move_rules = get_mail_move_rules() args.mail_move_age = get_mail_move_age() args.mail_move_rename = get_mail_move_rename() with Database() as database: configured_filter_chain = get_filter_chain(database) if args.enable_filters: args.enable_filters = args.enable_filters.split(',') all_filters_set = set(all_filters.keys()) enabled_filters_set = set(args.enable_filters) if not all_filters_set.issuperset(enabled_filters_set): sys.exit('Unknown filter(s) selected: %s' % (' '.join( enabled_filters_set.difference(all_filters_set)))) args.enable_filters = [ all_filters[filter_name](database) for filter_name in args.enable_filters ] else: args.enable_filters = configured_filter_chain inner_main(args, database, query_string)
def main(): options, args = option_parser.parse_args() no_actions = len( filter_compat(None, (options.tag, options.watch, options.update or options.update_reference, options.learn, options.classify, options.move_mails))) if no_actions == 0: sys.exit('You need to specify an action') elif no_actions > 1: sys.exit( 'Please specify exactly one action (both update actions can be given at once)' ) no_query_modifiers = len( filter_compat(None, (options.all, options.new, args))) if no_query_modifiers == 0 and not \ (options.update or options.update_reference or options.watch) and not \ options.move_mails: sys.exit('You need to specify one of --new, --all or a query string') elif no_query_modifiers > 1: sys.exit('Please specify either --all, --new or a query string') read_notmuch_settings(options.notmuch_config) if options.new: query_string = get_notmuch_new_query() elif options.all: query_string = '' elif not (options.update or options.update_reference): query_string = ' '.join(args) elif options.update or options.update_reference: query_string = '%i..%i' % ( time.time() - options.reference_set_timeframe * 24 * 60 * 60, time.time()) else: sys.exit('Weird... please file a bug containing your command line.') loglevel = { 0: logging.WARNING, 1: logging.INFO, 2: logging.DEBUG, }[min(2, options.verbosity)] logging.basicConfig(level=loglevel) sys.path.insert(0, user_config_dir) # py2.7 compat hack glob_pattern = b'*.py' if sys.version_info[0] == 2 else '*.py' for file_name in glob.glob1(user_config_dir, glob_pattern): print('Importing user filter %r' % (file_name, )) __import__(file_name[:-3], level=0) if options.move_mails: options.mail_move_rules = get_mail_move_rules() options.mail_move_age = get_mail_move_age() options.mail_move_rename = get_mail_move_rename() with Database() as database: configured_filter_chain = get_filter_chain(database) if options.enable_filters: options.enable_filters = options.enable_filters.split(',') all_filters_set = set(all_filters.keys()) enabled_filters_set = set(options.enable_filters) if not all_filters_set.issuperset(enabled_filters_set): sys.exit('Unknown filter(s) selected: %s' % (' '.join( enabled_filters_set.difference(all_filters_set)))) options.enable_filters = [ all_filters[filter_name](database) for filter_name in options.enable_filters ] else: options.enable_filters = configured_filter_chain inner_main(options, database, query_string)
def main(): args = parser.parse_args() no_actions = len(filter_compat(None, ( args.tag, args.watch, args.move_mails ))) if no_actions == 0: sys.exit('You need to specify an action') elif no_actions > 1: sys.exit('Please specify exactly one action') no_query_modifiers = len(filter_compat(None, (args.all, args.new, args.query))) if no_query_modifiers == 0 and not args.watch \ and not args.move_mails: sys.exit('You need to specify one of --new, --all or a query string') elif no_query_modifiers > 1: sys.exit('Please specify either --all, --new or a query string') read_notmuch_settings(args.notmuch_config) if args.new: query_string = get_notmuch_new_query() elif args.all: query_string = '' else: query_string = ' '.join(args.query) loglevel = { 0: logging.WARNING, 1: logging.INFO, 2: logging.DEBUG, }[min(2, args.verbosity)] logging.basicConfig(level=loglevel) sys.path.insert(0, user_config_dir) # py2.7 compat hack glob_pattern = b'*.py' if sys.version_info[0] == 2 else '*.py' for file_name in glob.glob1(user_config_dir, glob_pattern): logging.info('Importing user filter %r' % (file_name, )) __import__(file_name[:-3], level=0) if args.move_mails: args.mail_move_rules = get_mail_move_rules() args.mail_move_age = get_mail_move_age() args.mail_move_rename = get_mail_move_rename() with Database() as database: configured_filter_chain = get_filter_chain(database) if args.enable_filters: args.enable_filters = args.enable_filters.split(',') all_filters_set = set(all_filters.keys()) enabled_filters_set = set(args.enable_filters) if not all_filters_set.issuperset(enabled_filters_set): sys.exit('Unknown filter(s) selected: %s' % (' '.join( enabled_filters_set.difference(all_filters_set)))) args.enable_filters = [all_filters[filter_name](database) for filter_name in args.enable_filters] else: args.enable_filters = configured_filter_chain inner_main(args, database, query_string)
def main(): options, args = option_parser.parse_args() no_actions = len(filter_compat(None, ( options.tag, options.watch, options.update or options.update_reference, options.learn, options.classify, options.move_mails ))) if no_actions == 0: sys.exit('You need to specify an action') elif no_actions > 1: sys.exit( 'Please specify exactly one action (both update actions can be given at once)') no_query_modifiers = len(filter_compat(None, (options.all, options.new, args))) if no_query_modifiers == 0 and not \ (options.update or options.update_reference or options.watch) and not \ options.move_mails: sys.exit('You need to specify one of --new, --all or a query string') elif no_query_modifiers > 1: sys.exit('Please specify either --all, --new or a query string') read_notmuch_settings(options.notmuch_config) if options.new: query_string = get_notmuch_new_query() elif options.all: query_string = '' elif not (options.update or options.update_reference): query_string = ' '.join(args) elif options.update or options.update_reference: query_string = '%i..%i' % ( time.time() - options.reference_set_timeframe * 24 * 60 * 60, time.time()) else: sys.exit('Weird... please file a bug containing your command line.') loglevel = { 0: logging.WARNING, 1: logging.INFO, 2: logging.DEBUG, }[min(2, options.verbosity)] logging.basicConfig(level=loglevel) sys.path.insert(0, user_config_dir) # py2.7 compat hack glob_pattern = b'*.py' if sys.version_info[0] == 2 else '*.py' for file_name in glob.glob1(user_config_dir, glob_pattern): print('Importing user filter %r' % (file_name, )) __import__(file_name[:-3], level=0) if options.move_mails: options.mail_move_rules = get_mail_move_rules() options.mail_move_age = get_mail_move_age() with Database() as database: configured_filter_chain = get_filter_chain(database) if options.enable_filters: options.enable_filters = options.enable_filters.split(',') all_filters_set = set(all_filters.keys()) enabled_filters_set = set(options.enable_filters) if not all_filters_set.issuperset(enabled_filters_set): sys.exit('Unknown filter(s) selected: %s' % (' '.join( enabled_filters_set.difference(all_filters_set)))) options.enable_filters = [all_filters[ filter_name]() for filter_name in options.enable_filters] else: options.enable_filters = configured_filter_chain inner_main(options, database, query_string)
def query(self): """ Need to read the notmuch settings first. Using a property here so that the setting is looked up on demand. """ return get_notmuch_new_query()