Bug #8468: Another stab at renaming fix
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 5 Aug 2009 21:54:50 +0000 (15:54 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 5 Aug 2009 21:58:16 +0000 (15:58 -0600)
imp/folders.php
imp/lib/IMP.php

index 8ddab4a..57739a9 100644 (file)
@@ -186,15 +186,27 @@ case 'create_folder':
 
 case 'rename_folder':
     // $old_names already in UTF7-IMAP
-    $old_names = explode("\n", Horde_Util::getFormData('old_names'));
-    $new_names = explode("\n", Horde_Util::getFormData('new_names'));
+    $old_names = array_map('trim', explode("\n", Horde_Util::getFormData('old_names')));
+    $new_names = array_map('trim', explode("\n", Horde_Util::getFormData('new_names')));
 
     $iMax = count($new_names);
     if (!empty($new_names) &&
         !empty($old_names) &&
         ($iMax == count($old_names))) {
         for ($i = 0; $i < $iMax; ++$i) {
-            $imp_folder->rename(trim($old_names[$i]), Horde_String::convertCharset(trim($new_names[$i]), $charset, 'UTF7-IMAP'));
+            $old_ns = $imp_imap->getNamespace($old_names[$i]);
+            $new = trim($new_names[$i], $old_ns['delimiter']);
+
+            /* If this is a personal namespace, then anything goes as far as
+             * the input. Just append the personal namespace to it. For
+             * others, add the  */
+            if (($old_ns['type'] == 'personal') ||
+                ($old_ns['name'] &&
+                 (stripos($new_names[$i], $old_ns['name']) !== 0))) {
+                $new = $old_ns['name'] . $new;
+            }
+
+            $imp_folder->rename($old_names[$i], Horde_String::convertCharset($new, $charset, 'UTF7-IMAP'));
         }
     }
     break;
index ff1a33e..495e235 100644 (file)
@@ -469,7 +469,7 @@ class IMP
         foreach ($sub_array as $key => $val) {
             if (stripos($out, $key) === 0) {
                 $len = strlen($key);
-                if ((strlen($out) == $len) || ($out[$len + 1] == $delimiter)) {
+                if ((strlen($out) == $len) || ($out[$len] == $delimiter)) {
                     $out = substr_replace($out, Horde_String::convertCharset($val, Horde_Nls::getCharset(), 'UTF7-IMAP'), 0, $len);
                     break;
                 }