3 commits - pykolab/auth pykolab/cli pykolab/imap

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Wed Jun 12 07:03:28 CEST 2013


 pykolab/auth/ldap/__init__.py       |   30 ++++++++++++++++++------------
 pykolab/cli/cmd_transfer_mailbox.py |   23 ++++++++++++++---------
 pykolab/imap/__init__.py            |   29 +++++++++++++++++++++++------
 3 files changed, 55 insertions(+), 27 deletions(-)

New commits:
commit e8703d9ad2f0f6bcf20a04529b179efaebc7d6d7
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Wed Jun 12 07:03:00 2013 +0200

    Rebase command transfer-mailbox so that it actually functions

diff --git a/pykolab/cli/cmd_transfer_mailbox.py b/pykolab/cli/cmd_transfer_mailbox.py
index 2176bde..4a4069a 100644
--- a/pykolab/cli/cmd_transfer_mailbox.py
+++ b/pykolab/cli/cmd_transfer_mailbox.py
@@ -21,6 +21,8 @@ import commands
 
 import pykolab
 
+from pykolab.auth import Auth
+from pykolab.imap import IMAP
 from pykolab.translate import _
 
 log = pykolab.getLogger('pykolab.cli')
@@ -41,22 +43,25 @@ def execute(*args, **kw):
     if len(conf.cli_args) > 0:
         target_partition = conf.cli_args.pop(0)
 
-    mbox_parts = imap.parse_mailfolder(mailfolder)
+    imap = IMAP()
+    imap.connect()
 
-    print "Mailbox parts:", mbox_parts
+    mbox_parts = imap.parse_mailfolder(mailfolder)
 
     if mbox_parts['domain'] == None:
+        domain = conf.get('kolab', 'primary_domain')
         user_identifier = mbox_parts['path_parts'][1]
     else:
+        domain = mbox_parts['domain']
         user_identifier = "%s@%s" % (mbox_parts['path_parts'][1], mbox_parts['domain'])
 
-    print "User Identifier:", user_identifier
-
-    user = auth.find_user("mail", user_identifier)
+    source_server = imap.user_mailbox_server(mailfolder)
+    imap.connect(server=source_server)
+    imap.imap.xfer(mailfolder, target_server)
 
-    print "User:", user
+    auth = Auth()
+    auth.connect()
 
-    imap.connect()
-    imap.imap.xfer(mailfolder, target_server)
+    user = auth.find_recipient(user_identifier)
 
-    auth.set_user_attribute(mbox_parts['domain'], user, "mailHost", target_server)
+    auth.set_entry_attributes(domain, user, {'mailhost': target_server})


commit 2685e075e05a080d9b9a1108674ff658c411857a
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Wed Jun 12 07:02:16 2013 +0200

    When connecting to a specific server, actually connect to that specific server
    Calling disconnect() should not traceback should no current connection exist
    self.namespaces() may not be successful as the user to login as has no mailbox yet (murder)

diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index 9d065a5..fa71014 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -111,6 +111,7 @@ class IMAP(object):
                 if conf.has_section(domain) and conf.has_option(domain, 'imap_uri'):
                     uri = conf.get(domain, 'imap_uri')
 
+        scheme = None
         hostname = None
         port = None
 
@@ -131,6 +132,11 @@ class IMAP(object):
         if port == None:
             port = 993
 
+        if scheme == None or scheme == "":
+            scheme = 'imaps'
+
+        uri = '%s://%s:%s' % (scheme, hostname, port)
+
         # Get the credentials
         admin_login = conf.get(backend, 'admin_login')
         admin_password = conf.get(backend, 'admin_password')
@@ -167,7 +173,7 @@ class IMAP(object):
                     self._imap[hostname].logged_in = True
 
         else:
-            if not login and self._imap[hostname].logged_in == True:
+            if not login:
                 self.disconnect(hostname)
                 self.connect(uri=uri,login=False)
             elif login and not hasattr(self._imap[hostname],'logged_in'):
@@ -193,7 +199,8 @@ class IMAP(object):
     def disconnect(self, server=None):
         if server == None:
             # No server specified, but make sure self.imap is None anyways
-            del self.imap
+            if hasattr(self, 'imap'):
+                del self.imap
         else:
             if self._imap.has_key(server):
                 del self._imap[server]
@@ -445,11 +452,21 @@ class IMAP(object):
         admin_login = conf.get(backend, 'admin_login')
         admin_password = conf.get(backend, 'admin_password')
 
-        self.connect(login=False)
-
-        self.login_plain(admin_login, admin_password, folder)
+        success = False
+        while not success:
+            try:
 
-        (personal, other, shared) = self.namespaces()
+                self.disconnect()
+                self.connect(login=False)
+                self.login_plain(admin_login, admin_password, folder)
+                (personal, other, shared) = self.namespaces()
+                success = True
+            except Exception, errmsg:
+                log.debug(_("Waiting for the Cyrus murder to settle... %r") % (errmsg))
+                if conf.debuglevel > 8:
+                    import traceback
+                    traceback.print_exc()
+                time.sleep(0.5)
 
         for additional_folder in additional_folders.keys():
             _add_folder = {}


commit 8087206f4e8a8f683f50e5cc26407ed1f2994483
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Wed Jun 12 06:57:27 2013 +0200

    Escape the actual search in a try/except printing a stack trace should anything go wrong

diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 29448a5..e0118d1 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -889,18 +889,24 @@ class LDAP(pykolab.base.Base):
 
         log.debug(_("Synchronization is searching against base DN: %s") % (base_dn), level=8)
 
-        self._search(
-                base_dn,
-                filterstr=_filter,
-                attrlist=[
-                        '*',
-                        self.config_get('unique_attribute'),
-                        conf.get('cyrus-sasl', 'result_attribute'),
-                        'modifytimestamp'
-                    ],
-                override_search=override_search,
-                callback=self._synchronize_callback,
-            )
+        try:
+            self._search(
+                    base_dn,
+                    filterstr=_filter,
+                    attrlist=[
+                            '*',
+                            self.config_get('unique_attribute'),
+                            conf.get('cyrus-sasl', 'result_attribute'),
+                            'modifytimestamp'
+                        ],
+                    override_search=override_search,
+                    callback=self._synchronize_callback,
+                )
+        except Exception, errmsg:
+            log.error("Exception occurred: %r" % (errmsg))
+            if conf.debuglevel > 8:
+                import traceback
+                traceback.print_exc()
 
     def user_quota(self, entry_id, folder):
         default_quota = self.config_get('default_quota')





More information about the commits mailing list