15 commits - configure.ac pykolab/auth pykolab/cli pykolab/Makefile.am pykolab.spec.in pykolab/tests pykolab/wap_client
Jeroen van Meeuwen
vanmeeuwen at kolabsys.com
Sun May 13 18:36:09 CEST 2012
configure.ac | 4
pykolab.spec.in | 5
pykolab/Makefile.am | 12 -
pykolab/auth/__init__.py | 9 +
pykolab/auth/ldap/__init__.py | 5
pykolab/cli/cmd_create_mailbox.py | 29 ++++
pykolab/cli/cmd_delete_mailbox.py | 5
pykolab/cli/cmd_list_mailboxes.py | 31 +++-
pykolab/cli/cmd_remove_mailaddress.py | 71 ++++++++---
pykolab/cli/commands.py | 12 +
pykolab/tests/__init__.py | 72 -----------
pykolab/tests/imap/test_create_mailbox.py | 44 ------
pykolab/tests/imap/test_login.py | 61 ---------
pykolab/tests/imap/test_login_admin.py | 40 ------
pykolab/tests/tests.py | 192 ------------------------------
pykolab/tests/wap/test_login.py | 40 ------
pykolab/wap_client/__init__.py | 33 ++---
17 files changed, 155 insertions(+), 510 deletions(-)
New commits:
commit 1eb236d0477a9f3b1d779cf12a24002e9d353c22
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 17:34:06 2012 +0100
Remove the tests that did not work anyway
diff --git a/pykolab.spec.in b/pykolab.spec.in
index 13a59a4..8f8e56c 100644
--- a/pykolab.spec.in
+++ b/pykolab.spec.in
@@ -263,7 +263,6 @@ rm -rf %{buildroot}
%{python_sitelib}/pykolab/plugins/defaultfolders
%{python_sitelib}/pykolab/plugins/dynamicquota
%{python_sitelib}/pykolab/plugins/recipientpolicy
-%exclude %{python_sitelib}/pykolab/tests/
%{python_sitelib}/kolab/
%{python_sitelib}/cyruslib.py*
%dir %{_localstatedir}/lib/kolab/
commit 846511d44d65c17e9d33526c355c7d322446bd14
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 17:33:32 2012 +0100
Remove the tests that didn't work anyway
diff --git a/pykolab/Makefile.am b/pykolab/Makefile.am
index 4ce35ac..937560c 100644
--- a/pykolab/Makefile.am
+++ b/pykolab/Makefile.am
@@ -61,15 +61,3 @@ pykolab_setup_PYTHON = \
setup/setup_zpush.py \
setup/__init__.py
-pykolab_testsdir = $(pythondir)/$(PACKAGE)/tests
-pykolab_tests_PYTHON = \
- $(wildcard tests/*.py)
-
-pykolab_tests_imapdir = $(pythondir)/$(PACKAGE)/tests/imap
-pykolab_tests_imap_PYTHON = \
- $(wildcard tests/imap/*.py)
-
-pykolab_tests_wapdir = $(pythondir)/$(PACKAGE)/tests/wap
-pykolab_tests_wap_PYTHON = \
- $(wildcard tests/wap/*.py)
-
commit 72199df0fed7582faccd784cae856cc3547a0a08
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 17:32:34 2012 +0100
Delete the tests that didn't work anyway
diff --git a/pykolab/tests/__init__.py b/pykolab/tests/__init__.py
deleted file mode 100644
index 3aefdc3..0000000
--- a/pykolab/tests/__init__.py
+++ /dev/null
@@ -1,72 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com)
-#
-# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 3 or, at your option, any later version
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Library General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-
-import cyruslib
-import datetime
-import os
-import random
-import time
-
-import pykolab
-
-from pykolab.constants import *
-from pykolab.translate import _
-
-log = pykolab.getLogger('pykolab.tests')
-conf = pykolab.getConf()
-
-class Tests(object):
- def __init__(self):
- import tests
- tests.__init__()
-
- test_group = conf.add_cli_parser_option_group(_("Test Options"))
-
- test_group.add_option( "--suite",
- dest = "test_suites",
- action = "append",
- default = [],
- help = _("Run tests in suite SUITE. Implies a certain set of items being tested."),
- metavar = "SUITE")
-
- conf.finalize_conf()
-
- def run(self):
- if len(conf.test_suites) > 0:
- for test_suite in conf.test_suites:
- print test_suite
- else:
- to_execute = []
-
- arg_num = 0
- for arg in sys.argv[1:]:
- print "arg", arg
- arg_num += 1
- if not arg.startswith('-') and len(sys.argv) >= arg_num:
- if tests.tests.has_key(sys.argv[arg_num].replace('-','_')):
- print "tests.tests.has_key", sys.argv[arg_num].replace('-','_')
- to_execute.append(sys.argv[arg_num].replace('-','_'))
-
- print "to_execute", to_execute
- if len(to_execute) > 0:
- print "'_'.join(to_execute)", '_'.join(to_execute)
- tests.execute('_'.join(to_execute))
- else:
- tests.execute('help')
-
diff --git a/pykolab/tests/imap/__init__.py b/pykolab/tests/imap/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/pykolab/tests/imap/test_create_mailbox.py b/pykolab/tests/imap/test_create_mailbox.py
deleted file mode 100644
index e9a4901..0000000
--- a/pykolab/tests/imap/test_create_mailbox.py
+++ /dev/null
@@ -1,44 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com)
-#
-# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 3 or, at your option, any later version
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Library General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-
-from pykolab.tests import tests
-
-import pykolab
-
-from pykolab.translate import _
-
-log = pykolab.getLogger('pykolab.tests')
-conf = pykolab.getConf()
-
-auth = pykolab.auth
-imap = pykolab.imap
-
-def __init__():
- tests.register('create_mailbox', execute, group='imap', description=description())
-
-def description():
- return """Create a mailbox."""
-
-def execute(*args, **kw):
- return
- mailbox = conf.cli_args.pop(0)
-
- imap.connect()
- imap.cm(mailbox)
-
diff --git a/pykolab/tests/imap/test_login.py b/pykolab/tests/imap/test_login.py
deleted file mode 100644
index 7042415..0000000
--- a/pykolab/tests/imap/test_login.py
+++ /dev/null
@@ -1,61 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com)
-#
-# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 3 or, at your option, any later version
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Library General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-
-import time
-import traceback
-
-from pykolab.tests import tests
-
-import pykolab
-
-from pykolab.translate import _
-from pykolab import utils
-
-log = pykolab.getLogger('pykolab.tests')
-conf = pykolab.getConf()
-
-auth = pykolab.auth
-imap = pykolab.imap
-
-def __init__():
- tests.register('login', execute, group='imap', description=description())
-
-def description():
- return """Connect to IMAP and login."""
-
-def execute(*args, **kw):
- try:
- log.debug(_("Connecting at %s") % (time.time()), level=8)
- imap.connect(login=False)
- log.debug(_("Connected at %s") % (time.time()), level=8)
- except:
- raise TestFailureException, __file__
-
- try:
- log.debug(_("Logging in at %s") % (time.time()), level=8)
- imap.login('doe', password='0cvRKSdluPU4ewN')
- log.debug(_("Logged in at %s") % (time.time()), level=8)
- #imap.login('doe', password='bla')
- except:
- raise TestFailureException(__file__)
-
-class TestFailureException(BaseException):
- def __init__(self, test_file):
- log.error(_("Test failure in %s") % (test_file))
- utils.ask_confirmation('Would you like to log this as a bug?')
\ No newline at end of file
diff --git a/pykolab/tests/imap/test_login_admin.py b/pykolab/tests/imap/test_login_admin.py
deleted file mode 100644
index 6344bc7..0000000
--- a/pykolab/tests/imap/test_login_admin.py
+++ /dev/null
@@ -1,40 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com)
-#
-# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 3 or, at your option, any later version
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Library General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-
-from pykolab.tests import tests
-
-import pykolab
-
-from pykolab.translate import _
-
-log = pykolab.getLogger('pykolab.tests')
-conf = pykolab.getConf()
-
-auth = pykolab.auth
-imap = pykolab.imap
-
-def __init__():
- tests.register('login_admin', execute, group='imap', description=description())
-
-def description():
- return """Connect to IMAP and login as an administrator."""
-
-def execute(*args, **kw):
- imap.connect()
-
diff --git a/pykolab/tests/tests.py b/pykolab/tests/tests.py
deleted file mode 100644
index 1f72f3f..0000000
--- a/pykolab/tests/tests.py
+++ /dev/null
@@ -1,192 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com)
-#
-# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 3 or, at your option, any later version
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Library General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-
-import os
-import sys
-
-import pykolab
-
-from pykolab.translate import _
-
-log = pykolab.getLogger('pykolab.tests')
-conf = pykolab.getConf()
-
-tests = {}
-test_groups = {}
-
-def __init__():
- # We only want the base path
- tests_base_path = os.path.dirname(__file__)
-
- for tests_path, dirnames, filenames in os.walk(tests_base_path):
- if not tests_path == tests_base_path:
- continue
-
- for filename in filenames:
- #print filename
- if filename.startswith('test_') and filename.endswith('.py'):
- module_name = filename.replace('.py','')
- test_name = module_name.replace('test_', '')
- #print "exec(\"from %s import __init__ as %s_register\"" % (module_name,test_name)
- exec("from %s import __init__ as %s_register" % (module_name,test_name))
- exec("%s_register()" % (test_name))
-
- for dirname in dirnames:
- register_group(tests_path, dirname)
-
- register('help', list_tests, description=_("List tests"))
-
-def list_tests(*args, **kw):
- """
- List tests
- """
-
- __tests = {}
-
- for test in tests.keys():
- if isinstance(test, tuple):
- test_group, test = test
- __tests[test_group] = {
- test: tests[(test_group,test)]
- }
- else:
- __tests[test] = tests[test]
-
- _tests = __tests.keys()
- _tests.sort()
-
- for _test in _tests:
- if not __tests[_test].has_key('group'):
- if __tests[_test].has_key('function'):
- # This is a top-level test
- if not __tests[_test]['description'] == None:
- print "%-25s - %s" % (_test.replace('_','-'),__tests[_test]['description'])
- else:
- print "%-25s" % (_test.replace('_','-'))
-
- for _test in _tests:
- if not __tests[_test].has_key('function'):
- # This is a nested test
- print "\n" + _("Test Suite: %s") % (_test) + "\n"
- ___tests = __tests[_test].keys()
- ___tests.sort()
- for __test in ___tests:
- if not __tests[_test][__test]['description'] == None:
- print "%-4s%-21s - %s" % ('',__test.replace('_','-'),__tests[_test][__test]['description'])
- else:
- print "%-4s%-21s" % ('',__test.replace('_','-'))
-
-def execute(test_name, *args, **kw):
- print "tests:", tests
- print "test_name:", test_name
-
- if not tests.has_key(test_name):
- log.error(_("No such test."))
- sys.exit(1)
-
- if not tests[test_name].has_key('function') and \
- not tests[test_name].has_key('group'):
- log.error(_("No such test."))
- sys.exit(1)
-
- if tests[test_name].has_key('group'):
- group = tests[test_name]['group']
- _test_name = tests[test_name]['test_name']
- try:
- exec("from %s.test_%s import cli_options as %s_%s_cli_options" % (group,_test_name,group,test_name))
- exec("%s_%s_cli_options()" % (group,test_name))
- except ImportError, e:
- pass
-
- else:
- try:
- exec("from test_%s import cli_options as %s_cli_options" % (test_name,test_name))
- exec("%s_cli_options()" % (test_name))
- except ImportError, e:
- pass
-
- conf.finalize_conf()
-
- tests[test_name]['function'](conf.cli_args, kw)
-
-def register_group(dirname, module):
- tests_base_path = os.path.join(os.path.dirname(__file__), module)
-
- tests[module] = {}
-
- for tests_path, dirnames, filenames in os.walk(tests_base_path):
- if not tests_path == tests_base_path:
- continue
-
- for filename in filenames:
- if filename.startswith('test_') and filename.endswith('.py'):
- module_name = filename.replace('.py','')
- test_name = module_name.replace('test_', '')
- #print "exec(\"from %s.%s import __init__ as %s_%s_register\"" % (module,module_name,module,test_name)
- exec("from %s.%s import __init__ as %s_%s_register" % (module,module_name,module,test_name))
- exec("%s_%s_register()" % (module,test_name))
-
-def register(test_name, func, group=None, description=None, aliases=[]):
- if not group == None:
- test = "%s_%s" % (group,test_name)
- else:
- test = test_name
-
- #print "registering", test
-
- if isinstance(aliases, basestring):
- aliases = [aliases]
-
- if tests.has_key(test):
- log.fatal(_("Test '%s' already registered") % (test))
- sys.exit(1)
-
- if tests.has_key(test):
- log.fatal(_("Test '%s' already registered") % (test))
- sys.exit(1)
-
- if callable(func):
- if group == None:
- tests[test_name] = {
- 'function': func,
- 'description': description
- }
- else:
- tests[group][test_name] = {
- 'function': func,
- 'description': description
- }
-
- tests[test] = tests[group][test_name]
- tests[test]['group'] = group
- tests[test]['test_name'] = test_name
-
- for alias in aliases:
- tests[alias] = {
- 'function': func,
- 'description': _("Alias for %s") % (test_name)
- }
-
-##
-## Tests not yet implemented
-##
-
-def not_yet_implemented(*args, **kw):
- print _("Not yet implemented")
- sys.exit(1)
\ No newline at end of file
diff --git a/pykolab/tests/wap/__init__.py b/pykolab/tests/wap/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/pykolab/tests/wap/test_login.py b/pykolab/tests/wap/test_login.py
deleted file mode 100644
index 5eed57b..0000000
--- a/pykolab/tests/wap/test_login.py
+++ /dev/null
@@ -1,40 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com)
-#
-# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 3 or, at your option, any later version
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Library General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-
-from pykolab.tests import tests
-
-import pykolab
-
-from pykolab.translate import _
-
-log = pykolab.getLogger('pykolab.tests')
-conf = pykolab.getConf()
-
-auth = pykolab.auth
-imap = pykolab.imap
-
-def __init__():
- tests.register('login', execute, group='wap', description=description())
-
-def description():
- return """Log in to the Kolab Web Administration Panel API."""
-
-def execute(*args, **kw):
- return
-
commit 7e04f6ace9ca18fab5943a67d65bbc7519847db0
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 17:32:19 2012 +0100
Mature the wap_client module
diff --git a/pykolab/wap_client/__init__.py b/pykolab/wap_client/__init__.py
index 791ff43..998fcef 100644
--- a/pykolab/wap_client/__init__.py
+++ b/pykolab/wap_client/__init__.py
@@ -3,14 +3,17 @@ import json
import httplib
import sys
-sys.path.append('../..')
+import pykolab
from pykolab import utils
+log = pykolab.getLogger('pykolab.wap_client')
+conf = pykolab.getConf()
+
API_HOSTNAME = "localhost"
-API_PORT = "80"
API_SCHEME = "http"
-API_BASE = "/kolab-webadmin/api"
+API_PORT = 80
+API_BASE = "/kolab-webadmin/api/"
session_id = None
@@ -22,11 +25,20 @@ from request import request
def authenticate(username=None, password=None):
global session_id
+ conf_username = conf.get('ldap', 'service_bind_dn')
+ conf_password = conf.get('ldap', 'service_bind_pw')
+
if username == None:
- username = utils.ask_question("Login", "cn=Directory Manager")
+ username = utils.ask_question("Login", default=conf_username)
+
+ if username == conf_username:
+ password = conf_password
+
+ if username == conf.get('ldap', 'bind_dn'):
+ password = conf.get('ldap', 'bind_pw')
if password == None:
- password = utils.ask_question("Password", password=True)
+ password = utils.ask_question("Password", default=conf_password, password=True)
params = json.dumps(
{
@@ -123,8 +135,6 @@ def get_user_input():
'user_type_id': user_type_id
}
- print user_type_info
-
for attribute in user_type_info['form_fields'].keys():
params[attribute] = utils.ask_question(attribute)
@@ -178,18 +188,13 @@ def request(method, api_uri, params=None, headers={}):
response = conn.getresponse()
data = response.read()
- print method, api_uri, params
- print data
-
try:
response_data = json.loads(data)
except ValueError, e:
# Some data is not JSON
- print "Response data is not JSON"
+ log.error(_("Response data is not JSON"))
sys.exit(1)
- print response_data
-
if response_data['status'] == "OK":
del response_data['status']
return response_data['result']
@@ -330,8 +335,6 @@ def role_info(params=None):
'role': role
}
- print role
-
role = request('GET', 'role.info?role=%s' % (params['role'].keys()[0]))
return role
commit 774804d674a36733db51e76ce7da2353f7d5bf2c
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 17:31:09 2012 +0100
Update set_entry_attributes() to include the capability to delete and replace
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 6eed427..08b4e66 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -684,6 +684,11 @@ class LDAP(pykolab.base.Base):
for attribute in attrs.keys():
if entry.has_key(attribute) and entry[attribute] == None:
modlist.append((ldap.MOD_ADD, attribute, attrs[attribute]))
+ elif entry.has_key(attribute) and not entry[attribute] == None:
+ if attrs[attribute] == None:
+ modlist.append((ldap.MOD_DELETE, attribute, entry[attribute]))
+ else:
+ modlist.append((ldap.MOD_REPLACE, attribute, attrs[attribute]))
dn = entry_dn
self.ldap.modify_s(dn, modlist)
commit f73808f23fb87e46d8691e2bed204c0e57dc48dc
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 17:30:48 2012 +0100
Update cmd_remove_mailaddress
diff --git a/pykolab/cli/cmd_remove_mailaddress.py b/pykolab/cli/cmd_remove_mailaddress.py
index d6eb43b..19c4756 100644
--- a/pykolab/cli/cmd_remove_mailaddress.py
+++ b/pykolab/cli/cmd_remove_mailaddress.py
@@ -17,10 +17,14 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
+import sys
+
import commands
import pykolab
+from pykolab.auth import Auth
+from pykolab import utils
from pykolab.translate import _
log = pykolab.getLogger('pykolab.cli')
@@ -30,27 +34,60 @@ def __init__():
commands.register('remove_mail', execute, description=description())
def description():
- return """Remove a user's mail address."""
+ return """Remove a recipient's mail address."""
def execute(*args, **kw):
- uid = conf.cli_args.pop(0)
- email_address = conf.cli_args.pop(0)
+ try:
+ email_address = conf.cli_args.pop(0)
+ except IndexError, errmsg:
+ email_address = utils.ask_question("Email address to remove")
+
+ # Get the domain from the email address
+ if len(email_address.split('@')) > 1:
+ domain = email_address.split('@')[1]
+ else:
+ log.error(_("Invalid or unqualified email address."))
+ sys.exit(1)
+
+ auth = Auth()
+ auth.connect(domain=domain)
+ recipients = auth.find_recipient(email_address)
+
+ if len(recipients) == 0:
+ log.error(_("No recipient found for email address %r") % (email_address))
+ sys.exit(1)
+
+ log.debug(_("Found the following recipient(s): %r") % (recipients), level=8)
+
+ mail_attributes = conf.get_list(domain, 'mail_attributes')
+ if mail_attributes == None or len(mail_attributes) < 1:
+ mail_attributes = conf.get_list(conf.get('kolab', 'auth_mechanism'), 'mail_attributes')
+
+ log.debug(_("Using the following mail attributes: %r") % (mail_attributes), level=8)
+
+ if isinstance(recipients, basestring):
+ recipient = recipients
- user = auth.find_user('uid', uid)
- user = {
- 'dn': user
- }
+ # Only a single recipient found, remove the address
+ attributes = auth.get_entry_attributes(domain, recipient, mail_attributes)
- user['mail'] = auth.get_user_attribute('klab.cc', user, 'mail')
- user['mailalternateaddress'] = auth.get_user_attribute('klab.cc', user, 'mailalternateaddress')
+ # See which attribute holds the value we're trying to remove
+ for attribute in attributes.keys():
+ if isinstance(attributes[attribute], list):
+ if email_address in attributes[attribute]:
+ attributes[attribute].pop(attributes[attribute].index(email_address))
+ replace_attributes = {
+ attribute: attributes[attribute]
+ }
- if user['mail'] == email_address:
- auth.set_user_attribute('klab.cc', user, 'mail', '')
+ auth.set_entry_attributes(domain, recipient, replace_attributes)
+ else:
+ if email_address == attributes[attribute]:
+ auth.set_entry_attributes(domain, recipient, {attribute: None})
+ pass
- if email_address in user['mailalternateaddress']:
- _user_addresses = []
- for address in user['mailalternateaddress']:
- if not address == email_address:
- _user_addresses.append(address)
+ else:
+ print >> sys.stderr, _("Found the following recipients:")
- auth.set_user_attribute('klab.cc', user, 'mailAlternateAddress', _user_addresses)
+ for recipient in recipients:
+ print recipient
commit 417aaf699afca747ee41484a5c840a4ea4b3b2ff
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 17:30:00 2012 +0100
Wildcard %{python_sitelib}/cyruslib.py* because not all build systems byte-compile this file
diff --git a/pykolab.spec.in b/pykolab.spec.in
index a613765..13a59a4 100644
--- a/pykolab.spec.in
+++ b/pykolab.spec.in
@@ -265,9 +265,7 @@ rm -rf %{buildroot}
%{python_sitelib}/pykolab/plugins/recipientpolicy
%exclude %{python_sitelib}/pykolab/tests/
%{python_sitelib}/kolab/
-%{python_sitelib}/cyruslib.py
-%{python_sitelib}/cyruslib.pyc
-%{python_sitelib}/cyruslib.pyo
+%{python_sitelib}/cyruslib.py*
%dir %{_localstatedir}/lib/kolab/
%dir %{_localstatedir}/log/kolab/
commit 2d9745ef2f7c58302c7045f9cef13f4b45546956
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 17:29:36 2012 +0100
Add calls for set_entry_attribute() and set_entry_attributes()
diff --git a/pykolab/auth/__init__.py b/pykolab/auth/__init__.py
index 9054d01..3441394 100644
--- a/pykolab/auth/__init__.py
+++ b/pykolab/auth/__init__.py
@@ -236,8 +236,8 @@ class Auth(pykolab.base.Base):
def get_entry_attribute(self, domain, entry, attribute):
return self._auth.get_entry_attribute(entry, attribute)
- def get_entry_attributes(self, domain, entry, attribute):
- return self._auth.get_entry_attributes(entry, attribute)
+ def get_entry_attributes(self, domain, entry, attributes):
+ return self._auth.get_entry_attributes(entry, attributes)
def get_user_attribute(self, domain, user, attribute):
return self._auth.get_entry_attribute(user, attribute)
@@ -248,5 +248,11 @@ class Auth(pykolab.base.Base):
def search_mail_address(self, domain, mail_address):
return self._auth._search_mail_address(domain, mail_address)
+ def set_entry_attribute(self, domain, entry, attribute):
+ return self._auth.set_entry_attribute(entry, attribute)
+
+ def set_entry_attributes(self, domain, entry, attributes):
+ return self._auth.set_entry_attributes(entry, attributes)
+
def set_user_attribute(self, domain, user, attribute, value):
self._auth._set_user_attribute(user, attribute, value)
commit 48d6241fd3dd8c3b776677c73837636a4d74003f
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 17:07:29 2012 +0100
Correct commands referring to cmd_name
diff --git a/pykolab/cli/commands.py b/pykolab/cli/commands.py
index 9ea8da9..045bc15 100644
--- a/pykolab/cli/commands.py
+++ b/pykolab/cli/commands.py
@@ -165,11 +165,13 @@ def register(cmd_name, func, group=None, description=None, aliases=[]):
if callable(func):
if group == None:
commands[cmd_name] = {
+ 'cmd_name': cmd_name,
'function': func,
'description': description
}
else:
commands[group][cmd_name] = {
+ 'cmd_name': cmd_name,
'function': func,
'description': description
}
commit a6ec33719ebd910aaf826132489ce014af562923
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 17:05:29 2012 +0100
Correct cmd_list_mailboxes
diff --git a/pykolab/cli/cmd_list_mailboxes.py b/pykolab/cli/cmd_list_mailboxes.py
index 35e7a7b..185dea2 100644
--- a/pykolab/cli/cmd_list_mailboxes.py
+++ b/pykolab/cli/cmd_list_mailboxes.py
@@ -21,15 +21,19 @@ import commands
import pykolab
+from pykolab.imap import IMAP
from pykolab.translate import _
log = pykolab.getLogger('pykolab.cli')
conf = pykolab.getConf()
def __init__():
- commands.register('list_mailboxes', execute, description="List mailboxes.\n" + \
+ commands.register('list_mailboxes', execute, description=description(), aliases='lm')
+
+def description():
+ return "List mailboxes.\n" + \
"%-28s" % ('') + \
- "Use wildcards '*' and '%' for more control.\n")
+ "Use wildcards '*' and '%' for more control.\n"
def cli_options():
my_option_group = conf.add_cli_parser_option_group(_("CLI Options"))
@@ -43,17 +47,32 @@ def execute(*args, **kw):
"""
List mailboxes
"""
- try:
- searches = [ conf.cli_args.pop(1) ]
- except IndexError, e:
- #searches = [ 'DELETED/*', 'shared/*', 'user/*' ]
+
+ searches = []
+
+ # See if conf.cli_args components make sense.
+ for arg in conf.cli_args:
+ if arg == '*':
+ searches.append(arg)
+ if arg.startswith('user'):
+ searches.append(arg)
+ if arg.startswith('shared'):
+ searches.append(arg)
+ if arg.startswith('DELETED'):
+ searches.append(arg)
+ if arg.startswith('news'):
+ searches.append(arg)
+
+ if len(searches) == 0:
searches = [ '' ]
+ imap = IMAP()
imap.connect()
folders = []
for search in searches:
+ log.debug(_("Appending folder search for %r") % (search), level=8)
folders.extend(imap.lm(search))
for folder in folders:
commit 8547c0f2d92065e354986a7f53ce49098d994978
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 17:05:07 2012 +0100
Correct cmd_delete_mailbox.py
diff --git a/pykolab/cli/cmd_delete_mailbox.py b/pykolab/cli/cmd_delete_mailbox.py
index 973cd8b..0978b7e 100644
--- a/pykolab/cli/cmd_delete_mailbox.py
+++ b/pykolab/cli/cmd_delete_mailbox.py
@@ -17,10 +17,13 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
+import sys
+
import commands
import pykolab
+from pykolab.imap import IMAP
from pykolab.translate import _
log = pykolab.getLogger('pykolab.cli')
@@ -43,6 +46,8 @@ def execute(*args, **kw):
print >> sys.stderr, _("No mailbox specified")
sys.exit(1)
+ imap = IMAP()
+
imap.connect()
delete_folders = imap.lm(delete_folder)
for delete_folder in delete_folders:
commit 6b49689c5b655f4d262a1cd27956ab56ab06225f
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 17:04:38 2012 +0100
Enable use of alias commands with cli options
diff --git a/pykolab/cli/commands.py b/pykolab/cli/commands.py
index 7236b0b..9ea8da9 100644
--- a/pykolab/cli/commands.py
+++ b/pykolab/cli/commands.py
@@ -121,10 +121,11 @@ def execute(cmd_name, *args, **kw):
pass
else:
+ command_name = commands[cmd_name]['cmd_name']
try:
- exec("from cmd_%s import cli_options as %s_cli_options" % (cmd_name,cmd_name))
- exec("%s_cli_options()" % (cmd_name))
- except ImportError, e:
+ exec("from cmd_%s import cli_options as %s_cli_options" % (command_name,command_name))
+ exec("%s_cli_options()" % (command_name))
+ except ImportError, errmsg:
pass
conf.finalize_conf()
@@ -179,6 +180,7 @@ def register(cmd_name, func, group=None, description=None, aliases=[]):
for alias in aliases:
commands[alias] = {
+ 'cmd_name': cmd_name,
'function': func,
'description': _("Alias for %s") % (cmd_name)
}
@@ -189,4 +191,4 @@ def register(cmd_name, func, group=None, description=None, aliases=[]):
def not_yet_implemented(*args, **kw):
print _("Not yet implemented")
- sys.exit(1)
\ No newline at end of file
+ sys.exit(1)
commit bdaefc9e82e48f683c0a4a6f527c327cbc18ba65
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 17:03:29 2012 +0100
Correct cmd_create_mailbox.py
diff --git a/pykolab/cli/cmd_create_mailbox.py b/pykolab/cli/cmd_create_mailbox.py
index 20d9d6d..4ecc788 100644
--- a/pykolab/cli/cmd_create_mailbox.py
+++ b/pykolab/cli/cmd_create_mailbox.py
@@ -17,10 +17,13 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
+import sys
+
import commands
import pykolab
+from pykolab.imap import IMAP
from pykolab.translate import _
log = pykolab.getLogger('pykolab.cli')
@@ -29,12 +32,36 @@ conf = pykolab.getConf()
def __init__():
commands.register('create_mailbox', execute, description=description(), aliases='cm')
+def cli_options():
+ my_option_group = conf.add_cli_parser_option_group(_("CLI Options"))
+ my_option_group.add_option( '--metadata',
+ dest = "metadata",
+ action = "store",
+ default = None,
+ help = _("Set metadata for folder to ANNOTATION=VALUE"))
+
def description():
return """Create a mailbox or sub-folder of an existing mailbox."""
def execute(*args, **kw):
- mailbox = conf.cli_args.pop(0)
+ try:
+ mailbox = conf.cli_args.pop(0)
+ except IndexError, errmsg:
+ log.error(_("Invalid argument"))
+ sys.exit(1)
+ if not conf.metadata == None:
+ if len(conf.metadata.split('=')) == 2:
+ annotation = conf.metadata.split('=')[0]
+ annotation_value = conf.metadata.split('=')[1]
+ else:
+ log.error(_("Invalid argument for metadata"))
+ sys.exit(1)
+
+ imap = IMAP()
imap.connect()
imap.cm(mailbox)
+ if not conf.metadata == None:
+ imap.setannotation(mailbox, conf.metadata.split('=')[0], conf.metadata.split('=')[1])
+
commit a2dc01ba14aa4cbbef81f5438fa748c4ac14a436
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sun May 13 16:52:24 2012 +0100
Add Auth function get_entry_attributes()
diff --git a/pykolab/auth/__init__.py b/pykolab/auth/__init__.py
index 3c1b058..9054d01 100644
--- a/pykolab/auth/__init__.py
+++ b/pykolab/auth/__init__.py
@@ -236,6 +236,9 @@ class Auth(pykolab.base.Base):
def get_entry_attribute(self, domain, entry, attribute):
return self._auth.get_entry_attribute(entry, attribute)
+ def get_entry_attributes(self, domain, entry, attribute):
+ return self._auth.get_entry_attributes(entry, attribute)
+
def get_user_attribute(self, domain, user, attribute):
return self._auth.get_entry_attribute(user, attribute)
commit 0c934737995fa5633e7790230c0783b7dd7e0587
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Sat May 12 15:17:43 2012 +0100
master branch is deriving from pykolab-0.4, so bump the version number and set the pre-release release tag
diff --git a/configure.ac b/configure.ac
index 99346cb..0a85ed3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
-AC_INIT([pykolab], 0.4.0)
-AC_SUBST([RELEASE], 1)
+AC_INIT([pykolab], 0.5)
+AC_SUBST([RELEASE], 0.1)
AC_CONFIG_SRCDIR(pykolab/constants.py.in)
More information about the commits
mailing list