summaryrefslogtreecommitdiffstats
path: root/pykolab/imap
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-08-08 15:04:38 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-08-08 15:04:38 +0100
commitc8a39374cb97cb8ff70ff85b8613e74d77067f40 (patch)
tree8c8397fa0d656006bbb7fe93b8b572e1c3d30ea4 /pykolab/imap
parentfd3e861d85da2093be6d579e253e4290bf8ce932 (diff)
downloadpykolab-c8a39374cb97cb8ff70ff85b8613e74d77067f40.tar.gz
Add functions that support some of the new command line client commands
Diffstat (limited to 'pykolab/imap')
-rw-r--r--pykolab/imap/__init__.py50
-rw-r--r--pykolab/imap/cyrus.py5
2 files changed, 53 insertions, 2 deletions
diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index 65c232c..aee9148 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -212,6 +212,13 @@ class IMAP(object):
else:
raise AttributeError, _("%r has no attribute %s") % (self,name)
+ def get_metadata(self, folder):
+ """
+ Obtain all metadata entries on a folder
+ """
+
+ return self.imap.getannotation(folder, '*')
+
def namespaces(self):
"""
Obtain the namespaces.
@@ -255,6 +262,49 @@ class IMAP(object):
self.imap.sam(folder, identifier, acl)
+ def set_metadata(self, folder, metadata_path, metadata_value, shared=True):
+ """
+ Set a metadata entry on a folder
+ """
+
+ if metadata_path.startswith('/shared/'):
+ shared = True
+
+ if metadata_path.startswith('/shared/'):
+ metadata_path = metadata_path.replace('/shared/', '/')
+ elif metadata_path.startswith('/private/'):
+ shared = False
+ metadata_path = metadata_path.replace('/private/', '/')
+
+ backend = conf.get('kolab', 'imap_backend')
+
+ if not self.domain == None:
+ if conf.has_section(self.domain) and conf.has_option(self.domain, 'imap_backend'):
+ backend = conf.get(self.domain, 'imap_backend')
+
+ if not shared:
+ log.warning(_("Private annotations need to be set using the appropriate user account."))
+
+ admin_login = conf.get(backend, 'admin_login')
+
+ admin_acl = None
+
+ acls = self.list_acls(folder)
+ if acls.has_key(admin_login):
+ admin_acl = acls[admin_login]
+
+ if admin_acl == None:
+ self.set_acl(folder, admin_login, 'lrsipwa')
+ elif not 'w' in admin_acl:
+ self.set_acl(folder, admin_login, '%sw' % (admin_acl))
+
+ self.imap._setannotation(folder, metadata_path, metadata_value, shared)
+
+ if admin_acl == None:
+ self.set_acl(folder, admin_login, '')
+ elif not 'w' in admin_acl:
+ self.set_acl(folder, admin_login, admin_acl)
+
def shared_folder_create(self, folder_path, server=None):
"""
Create a shared folder.
diff --git a/pykolab/imap/cyrus.py b/pykolab/imap/cyrus.py
index af3e5b8..9b291bf 100644
--- a/pykolab/imap/cyrus.py
+++ b/pykolab/imap/cyrus.py
@@ -81,6 +81,7 @@ class Cyrus(cyruslib.CYRUS):
if conf.debuglevel > 8:
self.VERBOSE = True
+ self.m.debug = 5
# Initialize our variables
self.separator = self.SEP
@@ -217,7 +218,7 @@ class Cyrus(cyruslib.CYRUS):
def _getannotation(self, *args, **kw):
return self.getannotation(*args, **kw)
- def _setannotation(self, mailfolder, annotation, value):
+ def _setannotation(self, mailfolder, annotation, value, shared=False):
"""
Login to the actual backend server, then set annotation.
"""
@@ -228,7 +229,7 @@ class Cyrus(cyruslib.CYRUS):
#if annotation.startswith('/private'):
try:
- self.setannotation(mailfolder, annotation, value)
+ self.setannotation(mailfolder, annotation, value, shared)
except cyruslib.CYRUSError, e:
log.error(_("Could not set annotation %r on mail folder %r: %r") % (annotation,mailfolder,e))