aboutsummaryrefslogtreecommitdiffstats
path: root/listFolders.py
blob: b815d30e5020f748e69e6bf7fe56d37c2e42c34a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3.6

import configparser
import logging
import os.path

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'))
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 fld in data:
    spl_fld = fld.decode().split(sep)
    print(spl_fld[1].strip())