summaryrefslogtreecommitdiffstats
path: root/pykolab/imap
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-11-29 22:17:51 +0000
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-11-29 22:17:51 +0000
commit78d40271e62b5ada19b76849b545fb2044e53610 (patch)
tree62fb83e0954473564577f71859b9f02a7b1950ff /pykolab/imap
parent746901752b119f5c53ce6b334f863f7b248fc46d (diff)
downloadpykolab-78d40271e62b5ada19b76849b545fb2044e53610.tar.gz
Allow re-login to an existing IMAP server connection.
Outcomment the incomplete if statement in Cyrus
Diffstat (limited to 'pykolab/imap')
-rw-r--r--pykolab/imap/__init__.py59
-rw-r--r--pykolab/imap/cyrus.py3
2 files changed, 60 insertions, 2 deletions
diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index 4757768..9e66ad8 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -45,6 +45,22 @@ class IMAP(object):
self.inbox_folders = []
def connect(self, uri=None, domain=None, login=True):
+ """
+ Connect to the appropriate IMAP backend.
+
+ Supply a domain (name space) configured in the configuration file
+ as a section, with a setting 'imap_uri' to connect to a domain
+ specific IMAP server, or specify an URI to connect to that
+ particular IMAP server (in that order).
+
+ Routines sitting behind this will take into account Cyrus IMAP
+ Murder capabilities, brokering actions to take place against the
+ correct server (such as a 'xfer' which needs to happen against the
+ source backend).
+ """
+
+ # TODO: We are currently compatible with one IMAP backend technology per
+ # deployment.
backend = conf.get('kolab', 'imap_backend')
if not domain == None:
@@ -84,6 +100,7 @@ class IMAP(object):
if login:
log.debug(_("Logging on to Cyrus IMAP server %s") %(hostname), level=8)
self._imap[hostname].login(admin_login, admin_password)
+ self._imap[hostname].logged_in = True
elif backend == 'dovecot':
import dovecot
@@ -92,6 +109,7 @@ class IMAP(object):
if login:
log.debug(_("Logging on to Dovecot IMAP server %s") %(hostname), level=8)
self._imap[hostname].login(admin_login, admin_password)
+ self._imap[hostname].logged_in = True
else:
import imaplib
@@ -100,8 +118,17 @@ class IMAP(object):
if login:
log.debug(_("Logging on to generic IMAP server %s") %(hostname), level=8)
self._imap[hostname].login(admin_login, admin_password)
+ self._imap[hostname].logged_in = True
+
else:
- log.debug(_("Reusing existing IMAP server connection to %s") %(hostname), level=8)
+ if not login and self._imap[hostname].logged_in == True:
+ self.disconnect(hostname)
+ self.connect(uri=uri,login=False)
+ elif login and not hasattr(self._imap[hostname],'logged_in'):
+ self.disconnect(hostname)
+ self.connect(uri=uri)
+ else:
+ log.debug(_("Reusing existing IMAP server connection to %s") %(hostname), level=8)
# Set the newly created technology specific IMAP library as the current
# IMAP connection to be used.
@@ -110,7 +137,7 @@ class IMAP(object):
def disconnect(self, server=None):
if server == None:
# No server specified, but make sure self.imap is None anyways
- self.imap = None
+ del self.imap
else:
if self._imap.has_key(server):
del self._imap[server]
@@ -271,6 +298,34 @@ class IMAP(object):
"%s" %(additional_folders[additional_folder]["acls"][acl])
)
+ backend = conf.get('kolab', 'imap_backend')
+
+ if len(folder.split('@')) > 1:
+ domain = folder.split('@')[1]
+ else:
+ domain = None
+
+ if not domain == None:
+ if conf.has_section(domain) and conf.has_option(domain, 'imap_backend'):
+ backend = conf.get(domain, 'imap_backend')
+
+ if conf.has_section(domain) and conf.has_option(domain, 'imap_uri'):
+ uri = conf.get(domain, 'imap_uri')
+ else:
+ uri = None
+
+ # Get the credentials
+ 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)
+
+ for _folder in self.lm():
+ self.subscribe(_folder)
+
+ self.logout()
+
def set_user_folder_quota(self, users=[], primary_domain=None, secondary_domain=[], folders=[]):
"""
diff --git a/pykolab/imap/cyrus.py b/pykolab/imap/cyrus.py
index 38ac88e..d072428 100644
--- a/pykolab/imap/cyrus.py
+++ b/pykolab/imap/cyrus.py
@@ -191,6 +191,9 @@ class Cyrus(cyruslib.CYRUS):
imap.connect('imap://%s:143' %(server))
log.debug(_("Setting annotation %s on folder %s") %(annotation,mailfolder), level=8)
+
+ #if annotation.startswith('/private'):
+
imap.setannotation(mailfolder, annotation, value)
def _xfer(self, mailfolder, current_server, new_server):