summaryrefslogtreecommitdiffstats
path: root/pykolab
diff options
context:
space:
mode:
Diffstat (limited to 'pykolab')
-rw-r--r--pykolab/auth/ldap/__init__.py34
-rw-r--r--pykolab/cli/cmd_list_deleted_mailboxes.py78
-rw-r--r--pykolab/cli/cmd_list_mailboxes.py35
-rw-r--r--pykolab/imap/__init__.py49
-rw-r--r--pykolab/logger.py2
-rw-r--r--pykolab/setup/setup_mysql.py2
-rw-r--r--pykolab/setup/setup_roundcube.py2
7 files changed, 140 insertions, 62 deletions
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 67e9487..f76f684 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -1936,7 +1936,39 @@ class LDAP(Base):
cache.get_entry(self.domain, entry)
def _change_moddn_sharedfolder(self, entry, change):
- pass
+ result_attribute = 'cn'
+
+ old_cn = explode_dn(change['previous_dn'], True)[0]
+
+ if 'kolabtargetfolder' in entry and entry['kolabtargetfolder'] is not None:
+ new_folder_path = entry['kolabtargetfolder']
+ old_folder_path = old_cn
+
+ if '@' in entry['kolabtargetfolder']:
+ old_folder_path = "%s@%s" % (
+ old_folder_path,
+ entry['kolabtargetfolder'].split('@')[1]
+ )
+
+ else:
+ result_attribute = conf.get('cyrus-sasl', 'result_attribute')
+ if result_attribute in ['mail']:
+ new_folder_path = "%s@%s" % (entry['cn'], self.domain)
+ old_folder_path = "%s@%s" % (old_cn, self.domain)
+ else:
+ new_folder_path = "%s" % (entry['cn'])
+ old_folder_path = old_cn
+
+ if not new_folder_path.startswith('shared/'):
+ new_folder_path = "shared/%s" % (new_folder_path)
+
+ if not old_folder_path.startswith('shared/'):
+ old_folder_path = "shared/%s" % (old_folder_path)
+
+ log.debug("old folder path: %r" % (old_folder_path))
+ log.debug("new folder path: %r" % (new_folder_path))
+
+ self.imap.shared_folder_rename(old_folder_path, new_folder_path)
def _change_modify_None(self, entry, change):
pass
diff --git a/pykolab/cli/cmd_list_deleted_mailboxes.py b/pykolab/cli/cmd_list_deleted_mailboxes.py
index 55d90a6..6d07816 100644
--- a/pykolab/cli/cmd_list_deleted_mailboxes.py
+++ b/pykolab/cli/cmd_list_deleted_mailboxes.py
@@ -31,41 +31,75 @@ from pykolab.translate import _
log = pykolab.getLogger('pykolab.cli')
conf = pykolab.getConf()
+
def __init__():
commands.register('list_deleted_mailboxes', execute)
+
def cli_options():
my_option_group = conf.add_cli_parser_option_group(_("CLI Options"))
- my_option_group.add_option( '--raw',
- dest = "raw",
- action = "store_true",
- default = False,
- help = _("Display raw IMAP UTF-7 folder names"))
-
- my_option_group.add_option( '--server',
- dest = "connect_server",
- action = "store",
- default = None,
- metavar = "SERVER",
- help = _("List mailboxes on server SERVER only."))
+
+ my_option_group.add_option(
+ '--raw',
+ dest="raw",
+ action="store_true",
+ default=False,
+ help=_("Display raw IMAP UTF-7 folder names")
+ )
+
+ my_option_group.add_option(
+ '--server',
+ dest="connect_server",
+ action="store",
+ default=None,
+ metavar="SERVER",
+ help=_("List mailboxes on server SERVER only.")
+ )
+
def execute(*args, **kw):
"""
List deleted mailboxes
"""
- imap = IMAP()
- imap.connect()
-
- auth = Auth()
- auth.connect()
-
- domains = auth.list_domains()
folders = []
- for domain in list(set(domains.keys())):
- folders.extend(imap.lm("DELETED/*@%s" % (domain)))
+ searches = []
+
+ imap = IMAP()
- folders.extend(imap.lm("DELETED/*"))
+ if conf.connect_server is not None:
+ imap.connect(server=conf.connect_server)
+ else:
+ imap.connect()
+
+ # 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:
+ auth = Auth()
+ auth.connect()
+
+ domains = auth.list_domains()
+
+ folders = []
+ for domain in list(set(domains.keys())):
+ folders.extend(imap.lm("DELETED/*@%s" % (domain)))
+
+ folders.extend(imap.lm("DELETED/*"))
+ else:
+ for search in searches:
+ log.debug(_("Appending folder search for %r") % (search), level=8)
+ folders.extend(imap.lm(imap_utf7.encode(search)))
print "Deleted folders:"
diff --git a/pykolab/cli/cmd_list_mailboxes.py b/pykolab/cli/cmd_list_mailboxes.py
index 61dfb08..3b3bbd8 100644
--- a/pykolab/cli/cmd_list_mailboxes.py
+++ b/pykolab/cli/cmd_list_mailboxes.py
@@ -28,28 +28,37 @@ from pykolab.translate import _
log = pykolab.getLogger('pykolab.cli')
conf = pykolab.getConf()
+
def __init__():
commands.register('list_mailboxes', execute, description=description(), aliases='lm')
+
def description():
return "List mailboxes.\n" + \
"%-28s" % ('') + \
"Use wildcards '*' and '%' for more control.\n"
+
def cli_options():
my_option_group = conf.add_cli_parser_option_group(_("CLI Options"))
- my_option_group.add_option( '--raw',
- dest = "raw",
- action = "store_true",
- default = False,
- help = _("Display raw IMAP UTF-7 folder names"))
-
- my_option_group.add_option( '--server',
- dest = "connect_server",
- action = "store",
- default = None,
- metavar = "SERVER",
- help = _("List mailboxes on server SERVER only."))
+
+ my_option_group.add_option(
+ '--raw',
+ dest="raw",
+ action="store_true",
+ default=False,
+ help=_("Display raw IMAP UTF-7 folder names")
+ )
+
+ my_option_group.add_option(
+ '--server',
+ dest="connect_server",
+ action="store",
+ default=None,
+ metavar="SERVER",
+ help=_("List mailboxes on server SERVER only.")
+ )
+
def execute(*args, **kw):
"""
@@ -72,7 +81,7 @@ def execute(*args, **kw):
searches.append(arg)
if len(searches) == 0:
- searches = [ '' ]
+ searches = ['']
imap = IMAP()
diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index 3fc72d3..8ea23e7 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -43,14 +43,13 @@ class IMAP(object):
self.imap = None
def cleanup_acls(self, aci_subject):
- lm_suffix = ""
-
log.info(
_("Cleaning up ACL entries for %s across all folders") % (
aci_subject
)
)
+ lm_suffix = ""
if len(aci_subject.split('@')) > 1:
lm_suffix = "@%s" % (aci_subject.split('@')[1])
@@ -58,13 +57,6 @@ class IMAP(object):
user_folders = self.imap.lm("user/*%s" % (lm_suffix))
- log.debug(
- _("Cleaning up ACL entries referring to identifier %s") % (
- aci_subject
- ),
- level=5
- )
-
# For all folders (shared and user), ...
folders = user_folders + shared_folders
@@ -72,8 +64,8 @@ class IMAP(object):
# ... loop through them and ...
for folder in folders:
- # ... list the ACL entries -- but only if the folder still exists
- if self.imap.has_folder(folder):
+ try:
+ # ... list the ACL entries
acls = self.imap.lam(folder)
# For each ACL entry, see if we think it is a current, valid
@@ -96,13 +88,13 @@ class IMAP(object):
)
self.set_acl(folder, acl_entry, '')
- else:
- log.debug(
- _("Folder %r disappeared (ACL cleanup for %r") % (
+
+ except Exception, errmsg:
+ log.error(
+ _("Failed to read/set ACL on folder %s: %r") % (
folder,
- aci_subject
- ),
- level=8
+ errmsg
+ )
)
def connect(self, uri=None, server=None, domain=None, login=True):
@@ -429,12 +421,12 @@ class IMAP(object):
self.imap.sam(self.folder_utf7(folder), identifier, acl)
except Exception as errmsg:
log.error(
- _("Could not set ACL for %s on folder %s: %r") % (
- identifier,
- folder,
- errmsg
- )
+ _("Could not set ACL for %s on folder %s: %r") % (
+ identifier,
+ folder,
+ errmsg
)
+ )
def set_metadata(self, folder, metadata_path, metadata_value, shared=True):
"""
@@ -461,7 +453,7 @@ class IMAP(object):
if folder_name.startswith("shared%s" % (self.get_separator()) * 2):
folder_name = folder_name[7:]
- log.info(_("Creating new shared folder %s") %(folder_name))
+ log.info(_("Creating new shared folder %s") % (folder_name))
self.create_folder(folder_name, server)
def shared_folder_exists(self, folder_path):
@@ -476,6 +468,17 @@ class IMAP(object):
return self.has_folder(folder_name)
+ def shared_folder_rename(self, old, new):
+ if not self.has_folder(old):
+ log.error("Shared Folder rename error: Folder %s does not exist" % (old))
+ return
+
+ if self.has_folder(new):
+ log.error("Shared Folder rename error: Folder %s already exists" % (new))
+ return
+
+ self.imap._rename(old, new)
+
def shared_folder_set_type(self, folder_path, folder_type):
folder_name = 'shared%s%s' % (self.get_separator(), folder_path)
diff --git a/pykolab/logger.py b/pykolab/logger.py
index 1a826d9..2b857e2 100644
--- a/pykolab/logger.py
+++ b/pykolab/logger.py
@@ -213,7 +213,7 @@ class Logger(logging.Logger):
group_gid
)
- os.chmod(self.logfile, 660)
+ os.chmod(self.logfile, 0660)
except Exception as errmsg:
self.error(
diff --git a/pykolab/setup/setup_mysql.py b/pykolab/setup/setup_mysql.py
index c4cd90f..08b7b7c 100644
--- a/pykolab/setup/setup_mysql.py
+++ b/pykolab/setup/setup_mysql.py
@@ -256,7 +256,7 @@ host=%s
fp = open('/tmp/kolab-setup-my.cnf', 'w')
- os.chmod('/tmp/kolab-setup-my.cnf', 600)
+ os.chmod('/tmp/kolab-setup-my.cnf', 0600)
fp.write(data)
fp.close()
diff --git a/pykolab/setup/setup_roundcube.py b/pykolab/setup/setup_roundcube.py
index e10dcfe..47ac8fc 100644
--- a/pykolab/setup/setup_roundcube.py
+++ b/pykolab/setup/setup_roundcube.py
@@ -259,7 +259,7 @@ host=%s
""" % (mysql_root_password, conf.mysqlhost)
fp = open('/tmp/kolab-setup-my.cnf', 'w')
- os.chmod('/tmp/kolab-setup-my.cnf', 600)
+ os.chmod('/tmp/kolab-setup-my.cnf', 0600)
fp.write(data)
fp.close()