Branch 'pykolab-0.5' - 2 commits - pykolab/auth pykolab/imap
Jeroen van Meeuwen
vanmeeuwen at kolabsys.com
Sun Aug 5 21:25:25 CEST 2012
pykolab/auth/ldap/__init__.py | 32 +++++++++++++++++++++
pykolab/imap/__init__.py | 62 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 92 insertions(+), 2 deletions(-)
New commits:
commit 885e2be65bdd27ee40e11921a0a3a0a98746d644
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun Aug 5 20:12:11 2012 +0100
Make sure new users are subscribed to all folders in the personal namespace (#922)
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()
commit e9203b501fc18b684a37651341e34218db2b8c7c
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun Aug 5 15:33:50 2012 +0100
Prevent a singular alias (a basestring thanks to normalization) from being compared to a list, causing an endless modification loop for corner-case LDAP entries (#934)
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 8d82d6a..8c5a8e4 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -704,15 +704,44 @@ class LDAP(pykolab.base.Base):
log.debug(_("Recipient policy composed the following set of secondary " + \
"email addresses: %r") % (secondary_mail_addresses), level=8)
+
if not secondary_mail_addresses == None:
+ log.debug(
+ _("Secondary mail addresses that we want is not None: %r") % (
+ secondary_mail_addresses
+ ),
+ level=9
+ )
+
secondary_mail_addresses = list(set(secondary_mail_addresses))
+
# Avoid duplicates
while primary_mail_address in secondary_mail_addresses:
+ log.debug(
+ _("Avoiding the duplication of the primary mail " + \
+ "address %r in the list of secondary mail " + \
+ "addresses") % (primary_mail_address),
+ level=9
+ )
+
secondary_mail_addresses.pop(
secondary_mail_addresses.index(primary_mail_address)
)
+ log.debug(
+ _("Entry is getting secondary mail addresses: %r") % (
+ secondary_mail_addresses
+ ),
+ level=9
+ )
+
if not entry.has_key(secondary_mail_attribute):
+ log.debug(
+ _("Entry did not have any secondary mail " + \
+ "addresses in %r") % (secondary_mail_attribute),
+ level=9
+ )
+
if not len(secondary_mail_addresses) == 0:
self.set_entry_attribute(
entry,
@@ -722,6 +751,9 @@ class LDAP(pykolab.base.Base):
entry_modifications[secondary_mail_attribute] = secondary_mail_addresses
else:
+ if isinstance(entry[secondary_mail_attribute], basestring):
+ entry[secondary_mail_attribute] = list(set([entry[secondary_mail_attribute]]))
+
if not secondary_mail_addresses == entry[secondary_mail_attribute]:
self.set_entry_attribute(
entry,
More information about the commits
mailing list