summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2014-05-27 14:15:06 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2014-05-27 14:15:34 +0200
commit7a1bce58116882ad2e9498cafd641361209be6cf (patch)
tree7246d6271fb3458dad98c8996f324f495a6feeea
parentf7661c1904a3b2ca366cb31e690adabaf75950ed (diff)
downloadpykolab-7a1bce58116882ad2e9498cafd641361209be6cf.tar.gz
Make sure a mailbox is only renamed if it actually exists.
-rw-r--r--pykolab/auth/ldap/__init__.py32
-rw-r--r--pykolab/imap/__init__.py37
2 files changed, 42 insertions, 27 deletions
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index c0c3297..1714705 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -1346,7 +1346,7 @@ class LDAP(pykolab.base.Base):
)
else:
- folder = "user%s%s" % (self.imap.separator,entry[result_attribute].lower())
+ folder = "user%s%s" % (self.imap.get_separator(),entry[result_attribute].lower())
server = self.imap.user_mailbox_server(folder)
@@ -1676,19 +1676,31 @@ class LDAP(pykolab.base.Base):
if entry_changes.has_key(result_attribute):
if not entry_changes[result_attribute] == old_canon_attr:
- self.imap.user_mailbox_rename(
- old_canon_attr,
- entry_changes[result_attribute]
- )
+ if old_canon_attr == None:
+ self.imap.user_mailbox_create(
+ entry_changes[result_attribute]
+ )
+
+ else:
+ self.imap.user_mailbox_rename(
+ old_canon_attr,
+ entry_changes[result_attribute]
+ )
entry[result_attribute] = entry_changes[result_attribute]
cache.get_entry(self.domain, entry)
elif entry.has_key(result_attribute):
if not entry[result_attribute] == old_canon_attr:
- self.imap.user_mailbox_rename(
- old_canon_attr,
- entry[result_attribute]
- )
+ if old_canon_attr == None:
+ self.imap.user_mailbox_create(
+ entry[result_attribute]
+ )
+
+ else:
+ self.imap.user_mailbox_rename(
+ old_canon_attr,
+ entry[result_attribute]
+ )
cache.get_entry(self.domain, entry)
@@ -1864,7 +1876,7 @@ class LDAP(pykolab.base.Base):
server = self.imap.user_mailbox_server(folder)
else:
folder = "user%s%s" % (
- self.imap.separator,
+ self.imap.get_separator(),
entry[result_attribute]
)
diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index fbe515d..a72de30 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -381,10 +381,10 @@ class IMAP(object):
Create a shared folder.
"""
- folder_name = "shared%s%s" % (self.imap.separator, folder_path)
+ folder_name = "shared%s%s" % (self.get_separator(), folder_path)
# Correct folder_path being supplied with "shared/shared/" for example
- if folder_name.startswith("shared%s" % (self.imap.separator) * 2):
+ if folder_name.startswith("shared%s" % (self.get_separator()) * 2):
folder_name = folder_name[7:]
log.info(_("Creating new shared folder %s") %(folder_name))
@@ -394,19 +394,19 @@ class IMAP(object):
"""
Check if a shared mailbox exists.
"""
- folder_name = 'shared%s%s' % (self.imap.separator, folder_path)
+ folder_name = 'shared%s%s' % (self.get_separator(), folder_path)
# Correct folder_path being supplied with "shared/shared/" for example
- if folder_name.startswith("shared%s" % (self.imap.separator) * 2):
+ if folder_name.startswith("shared%s" % (self.get_separator()) * 2):
folder_name = folder_name[7:]
return self.has_folder(folder_name)
def shared_folder_set_type(self, folder_path, folder_type):
- folder_name = 'shared%s%s' % (self.imap.separator, folder_path)
+ folder_name = 'shared%s%s' % (self.get_separator(), folder_path)
# Correct folder_path being supplied with "shared/shared/" for example
- if folder_name.startswith("shared%s" % (self.imap.separator) * 2):
+ if folder_name.startswith("shared%s" % (self.get_separator()) * 2):
folder_name = folder_name[7:]
self.set_metadata(folder_name, '/shared/vendor/kolab/folder-type', folder_type)
@@ -416,10 +416,10 @@ class IMAP(object):
Create a shared folder.
"""
- folder_name = "shared%s%s" % (self.imap.separator, mailbox_base_name)
+ folder_name = "shared%s%s" % (self.get_separator(), mailbox_base_name)
# Correct folder_path being supplied with "shared/shared/" for example
- if folder_name.startswith("shared%s" % (self.imap.separator) * 2):
+ if folder_name.startswith("shared%s" % (self.get_separator()) * 2):
folder_name = folder_name[7:]
log.info(_("Creating new shared folder %s") %(mailbox_base_name))
@@ -429,10 +429,10 @@ class IMAP(object):
"""
Check if a shared mailbox exists.
"""
- folder_name = "shared%s%s" % (self.imap.separator, mailbox_base_name)
+ folder_name = "shared%s%s" % (self.get_separator(), mailbox_base_name)
# Correct folder_path being supplied with "shared/shared/" for example
- if folder_name.startswith("shared%s" % (self.imap.separator) * 2):
+ if folder_name.startswith("shared%s" % (self.get_separator()) * 2):
folder_name = folder_name[7:]
return self.has_folder(folder_name)
@@ -450,7 +450,7 @@ class IMAP(object):
log.warning(_("Downcasing mailbox name %r") % (mailbox_base_name))
mailbox_base_name = mailbox_base_name.lower()
- folder_name = "user%s%s" % (self.imap.separator, mailbox_base_name)
+ folder_name = "user%s%s" % (self.get_separator(), mailbox_base_name)
log.info(_("Creating new mailbox for user %s") %(mailbox_base_name))
self.create_folder(folder_name, server)
@@ -634,9 +634,9 @@ class IMAP(object):
folder_name = additional_folder
folder_name = "user%s%s%s%s%s" % (
- self.imap.separator,
+ self.get_separator(),
localpart,
- self.imap.separator,
+ self.get_separator(),
folder_name,
domain_suffix
)
@@ -660,7 +660,7 @@ class IMAP(object):
"""
self.connect()
- folder = "user%s%s" %(self.imap.separator,mailbox_base_name)
+ folder = "user%s%s" %(self.get_separator(),mailbox_base_name)
self.delete_mailfolder(folder)
self.cleanup_acls(mailbox_base_name)
@@ -672,7 +672,7 @@ class IMAP(object):
log.warning(_("Downcasing mailbox name %r") % (mailbox_base_name))
mailbox_base_name = mailbox_base_name.lower()
- return self.has_folder('user%s%s' %(self.imap.separator, mailbox_base_name))
+ return self.has_folder('user%s%s' %(self.get_separator(), mailbox_base_name))
def user_mailbox_quota(self, mailbox_quota):
pass
@@ -684,6 +684,9 @@ class IMAP(object):
if old_name == new_name and partition == None:
return
+ if not self.has_folder(old_name):
+ log.error(_("INBOX folder to rename (%s) does not exist") % (old_name))
+
if not self.has_folder(new_name) or not partition == None:
log.info(_("Renaming INBOX from %s to %s") % (old_name,new_name))
try:
@@ -1020,9 +1023,9 @@ class IMAP(object):
#if acceptable:
#folder_name = "%s@%s" % (folder.split(self.separator)[1].split('@')[0],folder.split('@')[1])
- folder_name = "%s@%s" % (folder.split(self.imap.separator)[1].split('@')[0],folder.split('@')[1])
+ folder_name = "%s@%s" % (folder.split(self.get_separator())[1].split('@')[0],folder.split('@')[1])
else:
- folder_name = "%s" % (folder.split(self.imap.separator)[1])
+ folder_name = "%s" % (folder.split(self.get_separator())[1])
if not folder_name == None:
if not folder_name in folders: