summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-11-21 13:50:29 +0000
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-11-21 13:50:29 +0000
commit9b0ffad77a623a088d7b6bff62661b2f4cc11248 (patch)
tree6b2421759e3aeb8fc18a511ff8e7662b10e5bdf1
parent48e2041fcbfaa8bc2b9fba96f083cd693e9cab80 (diff)
downloadpykolab-9b0ffad77a623a088d7b6bff62661b2f4cc11248.tar.gz
Add an option --user to allow list-mailbox-metadata and set-mailbox-metadata to be performed on behalf of the user (thus includes private annotations)
-rw-r--r--pykolab/cli/cmd_list_mailbox_metadata.py30
-rw-r--r--pykolab/cli/cmd_set_mailbox_metadata.py28
2 files changed, 56 insertions, 2 deletions
diff --git a/pykolab/cli/cmd_list_mailbox_metadata.py b/pykolab/cli/cmd_list_mailbox_metadata.py
index 87fe1b0..b430896 100644
--- a/pykolab/cli/cmd_list_mailbox_metadata.py
+++ b/pykolab/cli/cmd_list_mailbox_metadata.py
@@ -17,6 +17,8 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
+import sys
+
import commands
import pykolab
@@ -31,6 +33,17 @@ conf = pykolab.getConf()
def __init__():
commands.register('list_mailbox_metadata', execute, description=description())
+def cli_options():
+ my_option_group = conf.add_cli_parser_option_group(_("CLI Options"))
+ my_option_group.add_option(
+ '--user',
+ dest = "user",
+ action = "store",
+ default = None,
+ metavar = "USER",
+ help = _("List annotations as user USER")
+ )
+
def description():
return """Obtain a list of metadata entries on a folder."""
@@ -42,11 +55,26 @@ def execute(*args, **kw):
if len(folder.split('@')) > 1:
domain = folder.split('@')[1]
+ elif not conf.user == None and len(conf.user.split('@')) > 1:
+ domain = conf.user.split('@')[1]
else:
domain = conf.get('kolab', 'primary_domain')
imap = IMAP()
- imap.connect(domain=domain)
+
+ if not conf.user == None:
+ imap.connect(domain=domain, login=False)
+
+ backend = conf.get(domain, 'imap_backend')
+ if backend == None:
+ backend = conf.get('kolab', 'imap_backend')
+
+ admin_login = conf.get(backend, 'admin_login')
+ admin_password = conf.get(backend, 'admin_password')
+
+ imap.login_plain(admin_login, admin_password, conf.user)
+ else:
+ imap.connect(domain=domain)
if not imap.has_folder(folder):
print >> sys.stderr, _("No such folder %r") % (folder)
diff --git a/pykolab/cli/cmd_set_mailbox_metadata.py b/pykolab/cli/cmd_set_mailbox_metadata.py
index 9aa9b4e..2cade85 100644
--- a/pykolab/cli/cmd_set_mailbox_metadata.py
+++ b/pykolab/cli/cmd_set_mailbox_metadata.py
@@ -33,6 +33,17 @@ conf = pykolab.getConf()
def __init__():
commands.register('set_mailbox_metadata', execute, description=description())
+def cli_options():
+ my_option_group = conf.add_cli_parser_option_group(_("CLI Options"))
+ my_option_group.add_option(
+ '--user',
+ dest = "user",
+ action = "store",
+ default = None,
+ metavar = "USER",
+ help = _("Set annotation as user USER")
+ )
+
def description():
return """Set an metadata entry on a folder."""
@@ -57,11 +68,26 @@ def execute(*args, **kw):
if len(folder.split('@')) > 1:
domain = folder.split('@')[1]
+ elif not conf.user == None and len(conf.user.split('@')) > 1:
+ domain = conf.user.split('@')[1]
else:
domain = conf.get('kolab', 'primary_domain')
imap = IMAP()
- imap.connect(domain=domain)
+
+ if not conf.user == None:
+ imap.connect(domain=domain, login=False)
+
+ backend = conf.get(domain, 'imap_backend')
+ if backend == None:
+ backend = conf.get('kolab', 'imap_backend')
+
+ admin_login = conf.get(backend, 'admin_login')
+ admin_password = conf.get(backend, 'admin_password')
+
+ imap.login_plain(admin_login, admin_password, conf.user)
+ else:
+ imap.connect(domain=domain)
if not imap.has_folder(folder):
print >> sys.stderr, _("No such folder %r") % (folder)