8 commits - pykolab/auth pykolab/cli pykolab/wap_client tests/functional wallace/__init__.py wallace/module_resources.py wallace/modules.py

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Mon Dec 24 17:16:03 CET 2012


 pykolab/auth/__init__.py                              |    4 
 pykolab/auth/ldap/__init__.py                         |   14 +-
 pykolab/cli/cmd_sync.py                               |    2 
 pykolab/wap_client/__init__.py                        |    2 
 tests/functional/purge_users.py                       |   37 ++++++
 tests/functional/synchronize.py                       |    6 +
 tests/functional/test_kolabd/test_001_user_sync.py    |   65 ++++++++++--
 tests/functional/test_wallace/__init__.py             |    6 +
 tests/functional/test_wallace/test_001_user_add.py    |   96 ++++++++++++++++++
 tests/functional/test_wap_client/test_002_user_add.py |   59 +++--------
 wallace/__init__.py                                   |    9 +
 wallace/module_resources.py                           |   23 +---
 wallace/modules.py                                    |   29 +++--
 13 files changed, 270 insertions(+), 82 deletions(-)

New commits:
commit e2fe4e32e8864cde22c4e38adb5cd1058aca2f89
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Dec 24 17:15:48 2012 +0100

    Write and rebase a couple more tests

diff --git a/tests/functional/test_kolabd/test_001_user_sync.py b/tests/functional/test_kolabd/test_001_user_sync.py
index 2c3a144..e8e31bf 100644
--- a/tests/functional/test_kolabd/test_001_user_sync.py
+++ b/tests/functional/test_kolabd/test_001_user_sync.py
@@ -11,6 +11,9 @@ conf = pykolab.getConf()
 class TestKolabDaemon(unittest.TestCase):
     @classmethod
     def setup_class(self, *args, **kw):
+        from tests.functional.purge_users import purge_users
+        purge_users()
+
         self.user = {
                 'local': 'john.doe',
                 'domain': 'example.org'
@@ -19,6 +22,11 @@ class TestKolabDaemon(unittest.TestCase):
         from tests.functional.user_add import user_add
         user_add("John", "Doe")
 
+    @classmethod
+    def teardown_class(self, *args, **kw):
+        from tests.functional.purge_users import purge_users
+        purge_users()
+
     def test_001_user_recipient_policy(self):
         auth = Auth()
         auth.connect()
@@ -28,11 +36,43 @@ class TestKolabDaemon(unittest.TestCase):
 
         self.assertEqual(recipient, "uid=doe,ou=People,dc=example,dc=org")
 
-        result = wap_client.user_info(recipient)
-        self.assertEqual(result['mail'], 'john.doe at example.org')
-        self.assertEqual(result['alias'], ['doe at example.org', 'j.doe at example.org'])
+        result_before = wap_client.user_info(recipient)
+
+        # Ensure the synchronization is run even without a kolab daemon running.
+        auth.synchronize(mode='_paged_search')
+
+        result_after = wap_client.user_info(recipient)
+        self.assertEqual(result_after['mail'], 'john.doe at example.org')
+        self.assertEqual(result_before['alias'], ['doe at example.org', 'j.doe at example.org', 'john.doe at example.org'])
+        self.assertEqual(result_after['alias'], ['doe at example.org', 'j.doe at example.org'])
 
-    def test_002_user_mailbox_created(self):
+    def test_002_user_recipient_policy_duplicate(self):
+        from tests.functional.user_add import user_add
+        user = {
+                'local': 'jane.doe',
+                'domain': 'example.org'
+            }
+        user_add("Jane", "Doe")
+
+        auth = Auth()
+        auth.connect()
+        recipient = auth.find_recipient("%(local)s@%(domain)s" % (user))
+        if hasattr(self, 'assertIsInstance'):
+            self.assertIsInstance(recipient, str)
+
+        self.assertEqual(recipient, "uid=doe2,ou=People,dc=example,dc=org")
+
+        result_before = wap_client.user_info(recipient)
+
+        # Ensure the synchronization is run even without a kolab daemon running.
+        auth.synchronize(mode='_paged_search')
+
+        result_after = wap_client.user_info(recipient)
+        self.assertEqual(result_after['mail'], 'jane.doe at example.org')
+        self.assertEqual(result_before['alias'], ['doe2 at example.org', 'j.doe2 at example.org', 'jane.doe at example.org'])
+        self.assertEqual(result_after['alias'], ['doe2 at example.org', 'j.doe2 at example.org'])
+
+    def test_003_user_mailbox_created(self):
         time.sleep(2)
         imap = IMAP()
         imap.connect()
@@ -40,7 +80,7 @@ class TestKolabDaemon(unittest.TestCase):
         folders = imap.lm('user/%(local)s@%(domain)s' % (self.user))
         self.assertEqual(len(folders), 1)
 
-    def test_003_user_additional_folders_created(self):
+    def test_004_user_additional_folders_created(self):
         time.sleep(2)
         imap = IMAP()
         imap.connect()
@@ -51,7 +91,7 @@ class TestKolabDaemon(unittest.TestCase):
 
         self.assertEqual(len(folders), len(ac_folders.keys()))
 
-    def test_004_user_folder_annotations_set(self):
+    def test_005_user_folders_metadata_set(self):
         imap = IMAP()
         imap.connect()
 
@@ -62,18 +102,21 @@ class TestKolabDaemon(unittest.TestCase):
         folders.extend(imap.lm('user/%(local)s/*@%(domain)s' % (self.user)))
 
         for folder in folders:
-            annotation = imap.getannotation(folder)
-            print annotation
+            metadata = imap.get_metadata(folder)
+            print metadata
 
             folder_name = '/'.join(folder.split('/')[2:]).split('@')[0]
             if ac_folders.has_key(folder_name):
                 if ac_folders[folder_name].has_key('annotations'):
                     for _annotation in ac_folders[folder_name]['annotations'].keys():
+                        if _annotation.startswith('/private'):
+                            continue
+
                         _annotation_value = ac_folders[folder_name]['annotations'][_annotation]
-                        self.assertTrue(annotation[annotation.keys().pop()].has_key(_annotation))
-                        self.assertEqual(_annotation_value, annotation[annotation.keys().pop()][_annotation])
+                        self.assertTrue(metadata[metadata.keys().pop()].has_key(_annotation))
+                        self.assertEqual(_annotation_value, metadata[metadata.keys().pop()][_annotation])
 
-    def test_005_user_subscriptions(self):
+    def test_006_user_subscriptions(self):
         imap = IMAP()
         imap.connect(login=False)
         login = conf.get('cyrus-imap', 'admin_login')
diff --git a/tests/functional/test_wallace/__init__.py b/tests/functional/test_wallace/__init__.py
new file mode 100644
index 0000000..d7bf27f
--- /dev/null
+++ b/tests/functional/test_wallace/__init__.py
@@ -0,0 +1,6 @@
+import pykolab
+
+def setup_package():
+    conf = pykolab.getConf()
+    conf.finalize_conf(fatal=False)
+
diff --git a/tests/functional/test_wallace/test_001_user_add.py b/tests/functional/test_wallace/test_001_user_add.py
new file mode 100644
index 0000000..9a2c587
--- /dev/null
+++ b/tests/functional/test_wallace/test_001_user_add.py
@@ -0,0 +1,96 @@
+
+from email import message_from_string
+
+import time
+import unittest
+
+import pykolab
+from pykolab import wap_client
+from pykolab.auth import Auth
+from pykolab.imap import IMAP
+
+conf = pykolab.getConf()
+
+class TestUserAdd(unittest.TestCase):
+
+    @classmethod
+    def setup_class(self, *args, **kw):
+        from tests.functional.purge_users import purge_users
+        purge_users()
+
+        self.john = {
+                'local': 'john.doe',
+                'domain': 'example.org'
+            }
+
+        self.jane = {
+                'local': 'john.doe',
+                'domain': 'example.org'
+            }
+
+        from tests.functional.user_add import user_add
+        user_add("John", "Doe")
+        user_add("Jane", "Doe")
+        from tests.functional.synchronize import synchronize_once
+        synchronize_once()
+
+    @classmethod
+    def teardown_class(self, *args, **kw):
+        from tests.functional.purge_users import purge_users
+        purge_users()
+
+    def test_001_inbox_created(self):
+        imap = IMAP()
+        imap.connect()
+
+        folders = imap.lm('user/%(local)s@%(domain)s' % (self.john))
+        self.assertEqual(len(folders), 1)
+        
+        folders = imap.lm('user/%(local)s@%(domain)s' % (self.jane))
+        self.assertEqual(len(folders), 1)
+
+    def test_002_send_forwarded_email(self):
+        import smtplib
+        from email.MIMEMultipart import MIMEMultipart
+        from email.MIMEBase import MIMEBase
+        from email.MIMEText import MIMEText
+        from email.Utils import COMMASPACE, formatdate
+        from email import Encoders
+
+        smtp = smtplib.SMTP('localhost', 10026)
+        subject = "%s" % (time.time())
+        body = "This is a test message"
+        msg = MIMEMultipart()
+        msg['From'] = '"Doe, Jane" <jane.doe at example.org>'
+        msg['To'] = '"Doe, John" <john.doe at example.org>'
+        msg['Subject'] = subject
+        msg['Date'] = formatdate(localtime=True)
+        msg.attach(MIMEText(body))
+
+        send_to = 'jane.doe at example.org'
+        send_from = 'john.doe at example.org'
+
+        smtp.sendmail(send_from, send_to, msg.as_string())
+
+        imap = IMAP()
+        imap.connect()
+        imap.set_acl("user/jane.doe at example.org", "cyrus-admin", "lrs")
+        imap.imap.m.select("user/jane.doe at example.org")
+
+        found = False
+        max_tries = 20
+
+        while not found and max_tries > 0:
+            max_tries -= 1
+
+            typ, data = imap.imap.m.search(None, 'ALL')
+            for num in data[0].split():
+                typ, msg = imap.imap.m.fetch(num, '(RFC822)')
+                _msg = message_from_string(msg[0][1])
+                if _msg['Subject'] == subject:
+                    found = True
+
+            time.sleep(1)
+
+        if not found:
+            raise Exception
diff --git a/tests/functional/test_wap_client/test_002_user_add.py b/tests/functional/test_wap_client/test_002_user_add.py
index 84eeeb2..96c3de1 100644
--- a/tests/functional/test_wap_client/test_002_user_add.py
+++ b/tests/functional/test_wap_client/test_002_user_add.py
@@ -3,18 +3,17 @@ import unittest
 
 import pykolab
 from pykolab import wap_client
+from pykolab.auth import Auth
 from pykolab.imap import IMAP
 
 conf = pykolab.getConf()
 
 class TestUserAdd(unittest.TestCase):
+
     @classmethod
     def setup_class(self, *args, **kw):
-        conf.finalize_conf(fatal=False)
-
-        self.login = conf.get('ldap', 'bind_dn')
-        self.password = conf.get('ldap', 'bind_pw')
-        self.domain = conf.get('kolab', 'primary_domain')
+        from tests.functional.purge_users import purge_users
+        purge_users()
 
         self.user = {
                 'local': 'john.doe',
@@ -23,8 +22,16 @@ class TestUserAdd(unittest.TestCase):
 
         from tests.functional.user_add import user_add
         user_add("John", "Doe")
+        from tests.functional.synchronize import synchronize_once
+        synchronize_once()
+
+    @classmethod
+    def teardown_class(self, *args, **kw):
+        from tests.functional.purge_users import purge_users
+        purge_users()
 
     def test_001_inbox_created(self):
+
         time.sleep(2)
         imap = IMAP()
         imap.connect()
@@ -46,7 +53,7 @@ class TestUserAdd(unittest.TestCase):
 
         self.assertEqual(len(folders), len(ac_folders.keys()))
 
-    def test_003_folder_types_set(self):
+    def test_003_folders_metadata_set(self):
         imap = IMAP()
         imap.connect()
 
@@ -57,45 +64,17 @@ class TestUserAdd(unittest.TestCase):
         folders.extend(imap.lm('user/%(local)s/*@%(domain)s' % (self.user)))
 
         for folder in folders:
-            annotation = imap.getannotation(folder)
-            print annotation
+            metadata = imap.get_metadata(folder)
 
             folder_name = '/'.join(folder.split('/')[2:]).split('@')[0]
             if ac_folders.has_key(folder_name):
                 if ac_folders[folder_name].has_key('annotations'):
                     for _annotation in ac_folders[folder_name]['annotations'].keys():
-                        _annotation_value = ac_folders[folder_name]['annotations'][_annotation]
-                        self.assertTrue(annotation[annotation.keys().pop()].has_key(_annotation))
-                        self.assertEqual(_annotation_value, annotation[annotation.keys().pop()][_annotation])
-
-    @classmethod
-    def teardown_class(self):
-        time.sleep(2)
-
-        res_attr = conf.get('cyrus-sasl', 'result_attribute')
+                        if _annotation.startswith('/private/'):
+                            continue
 
-        exec("ac_folders = %s" % (conf.get_raw(conf.get('kolab', 'primary_domain'), 'autocreate_folders')))
-        expected_number_of_folders = len(ac_folders.keys()) + 1
-
-        users = []
-
-        result = wap_client.users_list()
-        for user in result['list'].keys():
-            user_info = wap_client.user_info(user)
-            users.append(user_info)
-            result = wap_client.user_delete({'user': user})
-
-        imap = IMAP()
-        imap.connect()
-
-        for user in users:
-            if len(user[res_attr].split('@')) > 1:
-                localpart = user[res_attr].split('@')[0]
-                domain = user[res_attr].split('@')[1]
-
-            folders = []
-            folders.extend(imap.lm('user/%s' % (user[res_attr])))
-            folders.extend(imap.lm('user/%s/*@%s' % (localpart,domain)))
+                        _annotation_value = ac_folders[folder_name]['annotations'][_annotation]
+                        self.assertTrue(metadata[metadata.keys().pop()].has_key(_annotation))
+                        self.assertEqual(_annotation_value, metadata[metadata.keys().pop()][_annotation])
 
-            # Expect folders length to be 0
 


commit 75a9dfa0bd9a892fb89c04b7affa8a0e4b318f96
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Dec 24 17:15:32 2012 +0100

    Repair wap client call user_add()

diff --git a/pykolab/wap_client/__init__.py b/pykolab/wap_client/__init__.py
index af66d36..373e636 100644
--- a/pykolab/wap_client/__init__.py
+++ b/pykolab/wap_client/__init__.py
@@ -295,7 +295,7 @@ def user_add(params=None):
 
     params = json.dumps(params)
 
-    return request('POST', 'user.add', params)
+    return request('POST', 'user.add', get=None, post=params)
 
 def user_delete(params=None):
     if params == None:


commit 2e72d7e1baa01ea0476435b515606f73a3387e8b
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Dec 24 17:15:11 2012 +0100

    Use the new no-persistent-search call to synchronize

diff --git a/pykolab/cli/cmd_sync.py b/pykolab/cli/cmd_sync.py
index 4ac675a..8beef3d 100644
--- a/pykolab/cli/cmd_sync.py
+++ b/pykolab/cli/cmd_sync.py
@@ -51,7 +51,7 @@ def execute(*args, **kw):
         log.debug(_("Running for domain %s") % (primary_domain), level=8)
         auth.connect(primary_domain)
         start_time = time.time()
-        auth.synchronize()
+        auth.synchronize(mode='_paged_search')
         end_time = time.time()
 
         log.info(_("Synchronizing users for %s took %d seconds")


commit a502a804cca9114b6c09e25cf81affbbda2b81a1
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Dec 24 17:14:42 2012 +0100

    Use the original SMTP communication exchange for recipients and senders (#1469)

diff --git a/wallace/modules.py b/wallace/modules.py
index 8a843e3..a20d80e 100644
--- a/wallace/modules.py
+++ b/wallace/modules.py
@@ -17,11 +17,12 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 #
 
+import json
 import os
 import sys
 import time
 
-from email import message_from_file
+from email import message_from_string
 from email.message import Message
 from email.mime.base import MIMEBase
 from email.mime.message import MIMEMessage
@@ -119,7 +120,8 @@ def cb_action_HOLD(module, filepath):
 
 def cb_action_DEFER(module, filepath):
     log.info(_("Deferring message in %s (by module %s)") % (filepath, module))
-    message = message_from_file(open(filepath, 'r'))
+    message = json.load(open(filepath, 'r'))
+    message = message_from_string(message['data'])
 
     internal_time = parsedate_tz(message.__getitem__('Date'))
     internal_time = time.mktime(internal_time[:9]) + internal_time[9]
@@ -161,11 +163,14 @@ def cb_action_DEFER(module, filepath):
 def cb_action_REJECT(module, filepath):
     log.info(_("Rejecting message in %s (by module %s)") % (filepath, module))
 
-    message = message_from_file(open(filepath, 'r'))
+    _message = json.load(open(filepath, 'r'))
+    message = message_from_string(_message['data'])
+
     envelope_sender = getaddresses(message.get_all('From', []))
 
     recipients = getaddresses(message.get_all('To', [])) + \
-            getaddresses(message.get_all('Cc', []))
+            getaddresses(message.get_all('Cc', [])) + \
+            _message['to']
 
     _recipients = []
 
@@ -246,11 +251,11 @@ X-Wallace-Result: REJECT
 
 def cb_action_ACCEPT(module, filepath):
     log.info(_("Accepting message in %s (by module %s)") % (filepath, module))
-    message = message_from_file(open(filepath, 'r'))
-    envelope_sender = getaddresses(message.get_all('From', []))
+    _message = json.load(open(filepath, 'r'))
 
-    recipients = getaddresses(message.get_all('To', [])) + \
-            getaddresses(message.get_all('Cc', []))
+    message = message_from_string("%s" %(str(_message['data'])))
+    sender = _message['from']
+    recipients = _message['to']
 
     smtp = smtplib.SMTP("localhost", 10027)
 
@@ -259,21 +264,25 @@ def cb_action_ACCEPT(module, filepath):
 
     try:
         smtp.sendmail(
-                formataddr(envelope_sender[0]),
-                [formataddr(recipient) for recipient in recipients],
+                sender,
+                recipients,
                 message.as_string()
             )
 
     except smtplib.SMTPDataError, errmsg:
+        log.error("SMTP Data Error, %r" % (errmsg))
         # DEFER
         pass
     except smtplib.SMTPHeloError, errmsg:
+        log.error("SMTP HELO Error, %r" % (errmsg))
         # DEFER
         pass
     except smtplib.SMTPRecipientsRefused, errmsg:
+        log.error("SMTP Recipient(s) Refused, %r" % (errmsg))
         # DEFER
         pass
     except smtplib.SMTPSenderRefused, errmsg:
+        log.error("SMTP Sender Refused, %r" % (errmsg))
         # DEFER
         pass
     finally:


commit f62ebee6000e79d6dc05cb2f005ed315a82d8dcb
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Dec 24 17:13:43 2012 +0100

    Adjust the resources module to match the new format in which files are written to the spool (#1469)

diff --git a/wallace/module_resources.py b/wallace/module_resources.py
index 8bd3e1f..5a66dda 100644
--- a/wallace/module_resources.py
+++ b/wallace/module_resources.py
@@ -28,7 +28,6 @@ import time
 from urlparse import urlparse
 import urllib
 
-from email import message_from_file
 from email import message_from_string
 from email.utils import formataddr
 from email.utils import getaddresses
@@ -121,10 +120,15 @@ def execute(*args, **kw):
                 os.path.basename(filepath)
             )
 
-        os.rename(filepath, new_filepath)
-        filepath = new_filepath
+        if not filepath == new_filepath:
+            log.debug("Renaming %r to %r" % (filepath, new_filepath))
+            os.rename(filepath, new_filepath)
+            filepath = new_filepath
 
-    message = message_from_file(open(filepath, 'r'))
+    _message = json.load(open(filepath, 'r'))
+    log.debug("Loaded message %r" % (_message), level=9)
+    message = message_from_string(_message['data'])
+    recipients = _message['to']
 
     any_itips = False
     any_resources = False
@@ -158,15 +162,8 @@ def execute(*args, **kw):
             possibly_any_resources = False
 
     if possibly_any_resources:
-        recipients = {
-                "To": getaddresses(message.get_all('To', [])),
-                "Cc": getaddresses(message.get_all('Cc', []))
-                # TODO: Are those all recipient addresses?
-            }
-        log.debug("Recipients: %r" % recipients)
-
-        for recipient in recipients['Cc'] + recipients['To']:
-            if not len(resource_record_from_email_address(recipient[1])) == 0:
+        for recipient in recipients:
+            if not len(resource_record_from_email_address(recipient)) == 0:
                 any_resources = True
 
     if any_resources:


commit 4ba6294b1ea93f42466d44f54726a8cf281cdd86
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Dec 24 17:11:54 2012 +0100

    Write out messages received to the spool as a JSON object that preserves the SMTP communication exchange (#1469)

diff --git a/wallace/__init__.py b/wallace/__init__.py
index 4b4792f..1e81eaa 100644
--- a/wallace/__init__.py
+++ b/wallace/__init__.py
@@ -21,6 +21,7 @@ import asyncore
 import binascii
 from distutils import version
 import grp
+import json
 import multiprocessing
 import os
 import pwd
@@ -241,6 +242,14 @@ class WallaceDaemon(object):
         """
         inheaders = 1
 
+        data = json.dumps(
+                {
+                        'from': mailfrom,
+                        'to': rcpttos,
+                        'data': data
+                   }
+            )
+
         (fp, filename) = tempfile.mkstemp(dir="/var/spool/pykolab/wallace/")
         os.write(fp, data)
         os.close(fp)


commit f40622f04115f2ecf8547f1dbebe0f88856492fa
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Dec 24 17:11:28 2012 +0100

    Allow synchronize() calls to specify to not use persistent searches

diff --git a/pykolab/auth/__init__.py b/pykolab/auth/__init__.py
index 359a0f6..6b07549 100644
--- a/pykolab/auth/__init__.py
+++ b/pykolab/auth/__init__.py
@@ -239,8 +239,8 @@ class Auth(pykolab.base.Base):
 
         return domains
 
-    def synchronize(self):
-        self._auth.synchronize()
+    def synchronize(self, mode=0):
+        self._auth.synchronize(mode=mode)
 
     def domain_default_quota(self, domain):
         return self._auth._domain_default_quota(domain)
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 4a696d9..61ae4a8 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -427,7 +427,6 @@ class LDAP(pykolab.base.Base):
 
         _filter = "%s%s%s" % (__filter_prefix,_filter,__filter_suffix)
 
-
         log.debug(_("Finding resource with filter %r") % (_filter), level=8)
 
         if len(_filter) <= 6:
@@ -515,12 +514,12 @@ class LDAP(pykolab.base.Base):
                 if _mail_attr == primary_mail_attribute:
                     log.debug(_("key %r is the prim. mail attr.") % (_mail_attr), level=8)
                     if not primary_mail == None:
-                        log.debug(_("prim. mail pol. is not empty"))
+                        log.debug(_("prim. mail pol. is not empty"), level=8)
                         want_attrs.append(_mail_attr)
                 elif _mail_attr == secondary_mail_attribute:
                     log.debug(_("key %r is the sec. mail attr.") % (_mail_attr), level=8)
                     if not secondary_mail == None:
-                        log.debug(_("sec. mail pol. is not empty"))
+                        log.debug(_("sec. mail pol. is not empty"), level=8)
                         want_attrs.append(_mail_attr)
 
         log.debug(_("Attributes %r are not yet available for entry %r") % (
@@ -838,7 +837,7 @@ class LDAP(pykolab.base.Base):
             except:
                 log.error(_("Could not update dn %r:\n%r") % (dn, modlist))
 
-    def synchronize(self):
+    def synchronize(self, mode=0):
         """
             Synchronize with LDAP
         """
@@ -851,6 +850,11 @@ class LDAP(pykolab.base.Base):
 
         log.debug(_("Using filter %r") % (_filter), level=8)
 
+        if not mode == 0:
+            override_search = mode
+        else:
+            override_search = False
+
         self._search(
                 self.config_get('base_dn'),
                 filterstr=_filter,
@@ -860,6 +864,7 @@ class LDAP(pykolab.base.Base):
                         conf.get('cyrus-sasl', 'result_attribute'),
                         'modifytimestamp'
                     ],
+                override_search=override_search,
                 callback=self._synchronize_callback,
             )
 
@@ -1886,6 +1891,7 @@ class LDAP(pykolab.base.Base):
             primary_domain=None,
             secondary_domains=[]
         ):
+
         _results = []
 
         psearch_server_controls = []


commit ffdafa9008dac20b2c4591321e444bd3cfc85c8f
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Dec 24 17:09:12 2012 +0100

    Provide purge_users and synchronize short cut calls

diff --git a/tests/functional/purge_users.py b/tests/functional/purge_users.py
new file mode 100644
index 0000000..1b18cb0
--- /dev/null
+++ b/tests/functional/purge_users.py
@@ -0,0 +1,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
+
diff --git a/tests/functional/synchronize.py b/tests/functional/synchronize.py
new file mode 100644
index 0000000..7046db2
--- /dev/null
+++ b/tests/functional/synchronize.py
@@ -0,0 +1,6 @@
+from pykolab.auth import Auth
+
+def synchronize_once():
+    auth = Auth()
+    auth.connect()
+    auth.synchronize(mode='_paged_search')





More information about the commits mailing list