diff options
Diffstat (limited to 'listFolders.py')
-rwxr-xr-x | listFolders.py | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/listFolders.py b/listFolders.py index b815d30..741ae41 100755 --- a/listFolders.py +++ b/listFolders.py @@ -10,6 +10,26 @@ logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s', level=logging.DEBUG) log = logging.getLogger('listFolders') +def list_folder(name, wildcards='*'): + ok, data = box.list(name, wildcards) + if ok != 'OK': + raise ServerError('Cannot list folder %s' % name) + return data[0] + +def get_separator(): + data = list_folder('pumpa') + + log.debug('data = %s (%s)', data, type(data)) + + if data is None: + data = list_folder('""', '""') + + data = data.decode().split(' ') + if len(data) == 3: + return data[1].strip(' "') + else: + raise ServerError('Cannot find folder separator from %s' % data) + config = configparser.ConfigParser() config.read(os.path.expanduser('~/.config/imap_archiver.cfg')) acc_name = config['general']['account'] @@ -20,13 +40,15 @@ ok, data = box.login(cfg['username'], cfg['password']) if ok != 'OK': raise IOError('Cannot login with credentials %s' % str(cfg)) -ok, data = box.list('""', '""') -sep = data[0].split()[1].decode() - -ok, data = box.list() -if ok != 'OK': - raise IOError('Cannot list known folders') - -for fld in data: - spl_fld = fld.decode().split(sep) - print(spl_fld[1].strip()) +sep = get_separator() +print('sep = %s' % sep) +# data = list_folder('""', '""') +# log.debug('data = %s', data) +# sep = data.split()[1].decode() +# +# data = list_folder('Work/punk') +# log.debug('ok = %s, data = %s (type %s)', ok, data, type(data)) + +# for fld in data: +# spl_fld = fld.decode().split(sep) +# print(spl_fld[1].strip()) |