diff options
author | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2013-06-12 07:02:16 +0200 |
---|---|---|
committer | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2013-06-12 07:03:23 +0200 |
commit | 2685e075e05a080d9b9a1108674ff658c411857a (patch) | |
tree | 65deb08bec6007bcf9f703c1b1af6980dc479368 | |
parent | 8087206f4e8a8f683f50e5cc26407ed1f2994483 (diff) | |
download | pykolab-2685e075e05a080d9b9a1108674ff658c411857a.tar.gz |
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)
-rw-r--r-- | pykolab/imap/__init__.py | 29 |
1 files changed, 23 insertions, 6 deletions
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 = {} |