summaryrefslogtreecommitdiffstats
path: root/pykolab/imap
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-08-05 20:12:11 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-08-05 20:12:11 +0100
commit05ebbb486e1f511d0003614e2e9b8682c49a64c7 (patch)
tree5bd55fcd7892943dc76f7af046dca8ca0d502492 /pykolab/imap
parent56a8ba9d57ff9432ec4b3299e8a7c18adcec6dad (diff)
downloadpykolab-05ebbb486e1f511d0003614e2e9b8682c49a64c7.tar.gz
Make sure new users are subscribed to all folders in the personal namespace (#922)
Diffstat (limited to 'pykolab/imap')
-rw-r--r--pykolab/imap/__init__.py62
1 files changed, 60 insertions, 2 deletions
diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index 25ec560..e5344c7 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -212,6 +212,42 @@ class IMAP(object):
else:
raise AttributeError, _("%r has no attribute %s") % (self,name)
+ def namespaces(self):
+ """
+ Obtain the namespaces.
+
+ Returns a tuple of:
+
+ (str(personal) [, str(other users) [, list(shared)]])
+ """
+
+ _personal = None
+ _other_users = None
+ _shared = None
+
+ (_response, _namespaces) = self.imap.m.namespace()
+
+ if len(_namespaces) == 1:
+ _namespaces = _namespaces[0]
+
+ _namespaces = re.split(r"\)\)\s\(\(", _namespaces)
+
+ _other_users = [
+ ''.join(_namespaces[1].replace('((','').replace('))','').split()[-1])
+ ]
+
+ if len(_namespaces) >= 3:
+ _shared = []
+ _shared.append(' '.join(_namespaces[2].replace('((','').replace('))','').split()[:-1]))
+
+ if len(_namespaces) >= 2:
+ _other_users = ' '.join(_namespaces[1].replace('((','').replace('))','').split()[:-1])
+
+ if len(_namespaces) >= 1:
+ _personal = _namespaces[0].replace('((','').replace('))','').split()[0]
+
+ return (_personal, _other_users, _shared)
+
def shared_folder_create(self, folder_path, server=None):
"""
Create a shared folder.
@@ -384,8 +420,30 @@ class IMAP(object):
self.connect(login=False)
self.login_plain(admin_login, admin_password, folder)
- for _folder in self.lm("%s/*%s" % (folder_name.split('@')[0],domain_suffix)):
- self.subscribe(_folder)
+ _tests = []
+
+ # Subscribe only to personal folders
+ (personal, other, shared) = self.namespaces()
+
+ if not other == None:
+ _tests.append(other)
+
+ if not shared == None:
+ for _shared in shared:
+ _tests.append(_shared)
+
+ for _folder in self.lm():
+ _subscribe = True
+
+ for _test in _tests:
+ if not _subscribe:
+ continue
+
+ if _folder.startswith(_test):
+ _subscribe = False
+
+ if _subscribe:
+ self.subscribe(_folder)
self.logout()