diff options
Diffstat (limited to 'archive_folder.py')
-rwxr-xr-x | archive_folder.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/archive_folder.py b/archive_folder.py index 7c1463f..4e0f8eb 100755 --- a/archive_folder.py +++ b/archive_folder.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3 # note http://docs.python.org/lib/module-doctest.html # resp. file:///usr/share/doc/python-docs-*/html/lib/module-doctest.html import argparse @@ -16,7 +16,7 @@ import sys from datetime import date, timedelta logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s', - stream=sys.stdout, level=logging.ERROR) + stream=sys.stdout, level=logging.INFO) log = logging.getLogger('imapArch') class ServerError(IOError): @@ -205,14 +205,15 @@ class Folder(object): class EmailServer(object): - def __init__(self, serverKey=None, archive_root=None): + def __init__(self, serverKey=None, archive_root=None, verbosity=0): config = self.get_config() acc_name = serverKey if serverKey is not None \ else config['general']['account'] self.cfg = dict(config.items(acc_name)) self.archive_root = archive_root self.box, self.all_folders = self.__login(**self.cfg) - # self.box.debug = 4 + if verbosity > 1: + self.box.debug = 4 def __login(self, host='localhost', username=None, password=None, ssl=None): box = imaplib.IMAP4_SSL(host=host) @@ -302,18 +303,24 @@ if __name__ == '__main__': help='Symbolic name of the server to be used') subp_arc.add_argument('folder', help='Folder which should be archived') subp_arc.add_argument('archive', help='Root folder to store annual archives to') + argp.add_argument('-v', action='count', dest='verbosity', default=0, + help='Verbosity of the operation (-vv shows IMAP chatter)') args = argp.parse_args() + log.debug('args = %s', args) + + if args.verbosity > 0: + log.setLevel(logging.DEBUG) if args.cmd == 'servers': config = EmailServer.get_config() sects = set(config.keys()) - {'DEFAULT', 'general'} print('Available servers:\n%s' % tuple(sects)) elif args.cmd == 'list': - myStore = EmailServer() + myStore = EmailServer(verbosity=args.verbosity) folders = myStore.list_folders() print('\n'.join(folders)) else: before = date.today() - timedelta(days=args.days) - with EmailServer(args.server, args.archive) as myStore: + with EmailServer(args.server, args.archive, verbosity=args.verbosity) as myStore: myStore.archive_folder(args.folder, before) |