summaryrefslogtreecommitdiffstats
path: root/pykolab/imap
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-07-06 18:24:09 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-07-06 18:24:09 +0100
commit6cc40d31ef0aab69b4d3868e277cfaddad226d9d (patch)
tree374d0e15d3c6a95b456dc5005f37c7de392f113c /pykolab/imap
parent00ef2f73974fd25b437f43d4feb978edcdd741e7 (diff)
downloadpykolab-6cc40d31ef0aab69b4d3868e277cfaddad226d9d.tar.gz
On el5, urlparse returns a tuple
Diffstat (limited to 'pykolab/imap')
-rw-r--r--pykolab/imap/__init__.py30
-rw-r--r--pykolab/imap/cyrus.py21
2 files changed, 32 insertions, 19 deletions
diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index 2b59a4b..aa40f06 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -52,40 +52,46 @@ class IMAP(object):
result = urlparse(uri)
+ if hasattr(result, 'hostname'):
+ hostname = result.hostname
+ else:
+ scheme = uri.split(':')[0]
+ (hostname, port) = uri.split('/')[2].split(':')
+
# Get the credentials
admin_login = conf.get(backend, 'admin_login')
admin_password = conf.get(backend, 'admin_password')
- if not self._imap.has_key(result.hostname):
+ if not self._imap.has_key(hostname):
if backend == 'cyrus-imap':
import cyrus
- self._imap[result.hostname] = cyrus.Cyrus(uri)
+ self._imap[hostname] = cyrus.Cyrus(uri)
# Actually connect
if login:
- log.debug(_("Logging on to Cyrus IMAP server %s") %(result.hostname), level=8)
- self._imap[result.hostname].login(admin_login, admin_password)
+ log.debug(_("Logging on to Cyrus IMAP server %s") %(hostname), level=8)
+ self._imap[hostname].login(admin_login, admin_password)
elif backend == 'dovecot':
import dovecot
- self._imap[result.hostname] = dovecot.Dovecot(uri)
+ self._imap[hostname] = dovecot.Dovecot(uri)
# Actually connect
if login:
- log.debug(_("Logging on to Dovecot IMAP server %s") %(result.hostname), level=8)
- self._imap[result.hostname].login(admin_login, admin_password)
+ log.debug(_("Logging on to Dovecot IMAP server %s") %(hostname), level=8)
+ self._imap[hostname].login(admin_login, admin_password)
else:
import imap
- self._imap[result.hostname] = imap.IMAP(uri)
+ self._imap[hostname] = imap.IMAP(uri)
# Actually connect
if login:
- log.debug(_("Logging on to generic IMAP server %s") %(result.hostname), level=8)
- self._imap[result.hostname].login(admin_login, admin_password)
+ log.debug(_("Logging on to generic IMAP server %s") %(hostname), level=8)
+ self._imap[hostname].login(admin_login, admin_password)
else:
- log.debug(_("Reusing existing IMAP server connection to %s") %(result.hostname), level=8)
+ 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.
- self.imap = self._imap[result.hostname]
+ self.imap = self._imap[hostname]
def disconnect(self, server=None):
if server == None:
diff --git a/pykolab/imap/cyrus.py b/pykolab/imap/cyrus.py
index 050507d..a03ccbd 100644
--- a/pykolab/imap/cyrus.py
+++ b/pykolab/imap/cyrus.py
@@ -50,20 +50,27 @@ class Cyrus(cyruslib.CYRUS):
"""
Initialize this class, but do not connect yet.
"""
+ port = None
+
result = urlparse(uri)
- # Complete the uri with the result to avoid cyruslib from bailing out.
- if not hasattr(result,'port'):
- if result.scheme == 'imap':
+ if hasattr(result, 'hostname'):
+ scheme = result.scheme
+ hostname = result.hostname
+ port = result.port
+ else:
+ scheme = uri.split(':')[0]
+ (hostname, port) = uri.split('/')[2].split(':')
+
+ if not port:
+ if scheme == 'imap':
port = 143
else:
port = 993
- else:
- port = result.port
- self.server = result.hostname
+ self.server = hostname
- self.uri = "%s://%s:%s" %(result.scheme,result.hostname,port)
+ self.uri = "%s://%s:%s" %(scheme,hostname,port)
cyruslib.CYRUS.__init__(self, self.uri)