summaryrefslogtreecommitdiffstats
path: root/tests/functional/purge_users.py
blob: 1b18cb057b7ddd953ccac8c41800d437fec9bea4 (plain)
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
33
34
35
36
37
import pykolab

from pykolab import wap_client
from pykolab.auth import Auth
from pykolab.imap import IMAP

conf = pykolab.getConf()

def purge_users():
    wap_client.authenticate(conf.get("ldap", "bind_dn"), conf.get("ldap", "bind_pw"))

    users = wap_client.users_list()
    for user in users['list']:
        wap_client.user_delete({'user': user})

    auth = Auth()
    domains = auth.list_domains()

    imap = IMAP()
    imap.connect()

    folders = []

    for domain,aliases in domains:
        folders.extend(imap.lm("user/%%@%s" % (domain)))

    for folder in folders:
        user = folder.replace('user/','')

        recipient = auth.find_recipient(user)

        if len(recipient) == 0 or recipient == []:
            try:
                imap.dm(folder)
            except:
                pass