diff options
Diffstat (limited to 'script')
-rwxr-xr-x | script/qmauth.py | 97 |
1 files changed, 52 insertions, 45 deletions
diff --git a/script/qmauth.py b/script/qmauth.py index c05e75f..2d78f81 100755 --- a/script/qmauth.py +++ b/script/qmauth.py @@ -371,56 +371,60 @@ def move_mail(f, mid, from_, to): return 1 -ap = ArgumentParser(allow_abbrev=False) -ap.add_argument('maildir_path', type=Path) -ap.add_argument('os_user') -ap.add_argument('mail_user') -sp = ap.add_subparsers(title='methods', required=True) - -sp_list = sp.add_parser('list') -sp_list.add_argument('folder', metavar='subfolder') -sp_list.add_argument('start', type=int) -sp_list.add_argument('end', type=int) -sp_list.add_argument('sortby', metavar='sort_by') -sp_list.set_defaults(run=list_mails) - -sp_count = sp.add_parser('count') -sp_count.add_argument('subfolder') -sp_count.set_defaults(run=count_mails) - -sp_read = sp.add_parser('read') -sp_read.add_argument('subfolder') -sp_read.add_argument('mid', metavar='message') -sp_read.set_defaults(run=read_mail) - -sp_raw = sp.add_parser('raw') -sp_raw.add_argument('subfolder') -sp_raw.add_argument('mid', metavar='message') -sp_raw.add_argument('path', default='') -sp_raw.set_defaults(run=raw_mail) - -sp_folders = sp.add_parser('folders') -sp_folders.set_defaults(run=folders) - -sp_move = sp.add_parser('move') -sp_move.add_argument('mid', metavar='message') -sp_move.add_argument('from_', metavar='from') -sp_move.add_argument('to') -sp_move.set_defaults(run=move_mail) - -sp_search = sp.add_parser('search') -sp_search.add_argument('pattern') -sp_search.add_argument('subfolder') -sp_search.set_defaults(run=search_mails) - - -if __name__ == '__main__': +def parse_arguments(): + ap = ArgumentParser(allow_abbrev=False) + ap.add_argument('maildir_path', type=Path) + ap.add_argument('os_user') + ap.add_argument('mail_user') + + sp = ap.add_subparsers(title='methods', required=True) + + sp_list = sp.add_parser('list') + sp_list.add_argument('folder', metavar='subfolder') + sp_list.add_argument('start', type=int) + sp_list.add_argument('end', type=int) + sp_list.add_argument('sortby', metavar='sort_by') + sp_list.set_defaults(run=list_mails) + + sp_count = sp.add_parser('count') + sp_count.add_argument('subfolder') + sp_count.set_defaults(run=count_mails) + + sp_read = sp.add_parser('read') + sp_read.add_argument('subfolder') + sp_read.add_argument('mid', metavar='message') + sp_read.set_defaults(run=read_mail) + + sp_raw = sp.add_parser('raw') + sp_raw.add_argument('subfolder') + sp_raw.add_argument('mid', metavar='message') + sp_raw.add_argument('path', default='') + sp_raw.set_defaults(run=raw_mail) + + sp_folders = sp.add_parser('folders') + sp_folders.set_defaults(run=folders) + + sp_move = sp.add_parser('move') + sp_move.add_argument('mid', metavar='message') + sp_move.add_argument('from_', metavar='from') + sp_move.add_argument('to') + sp_move.set_defaults(run=move_mail) + + sp_search = sp.add_parser('search') + sp_search.add_argument('pattern') + sp_search.add_argument('subfolder') + sp_search.set_defaults(run=search_mails) + + return vars(ap.parse_args()) + + +def main(): try: logging.basicConfig( level='INFO', format="%(levelname)s:"+str(getpid())+":%(message)s", ) - args = vars(ap.parse_args()) + args = parse_arguments() logging.debug("started with %s", args) s = startup( args.pop('maildir_path'), @@ -439,3 +443,6 @@ if __name__ == '__main__': except Exception: logging.exception("qmauth.py error") sysexit(4) + + +if __name__ == '__main__': main() |