aboutsummaryrefslogtreecommitdiffstats
path: root/listFolders.py
diff options
context:
space:
mode:
Diffstat (limited to 'listFolders.py')
-rwxr-xr-xlistFolders.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/listFolders.py b/listFolders.py
index db75596..b815d30 100755
--- a/listFolders.py
+++ b/listFolders.py
@@ -1,14 +1,32 @@
#!/usr/bin/env python3.6
import configparser
+import logging
import os.path
-import imapy
+import imaplib
+
+logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
+ level=logging.DEBUG)
+log = logging.getLogger('listFolders')
config = configparser.ConfigParser()
config.read(os.path.expanduser('~/.config/imap_archiver.cfg'))
-cfg = dict(config.items(config['general']['account']))
-box = imapy.connect(**cfg)
+acc_name = config['general']['account']
+cfg = dict(config.items(acc_name))
+
+box = imaplib.IMAP4_SSL(host=cfg['host'])
+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 fold in box.folders():
- print(fold)
+for fld in data:
+ spl_fld = fld.decode().split(sep)
+ print(spl_fld[1].strip())