From 5b9484944bd31302510bc2223a8ba6f1f5b826bd Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 5 Aug 2009 15:54:50 -0600 Subject: [PATCH] Bug #8468: Another stab at renaming fix --- imp/folders.php | 18 +++++++++++++++--- imp/lib/IMP.php | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/imp/folders.php b/imp/folders.php index 8ddab4ade..57739a9c5 100644 --- a/imp/folders.php +++ b/imp/folders.php @@ -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; diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index ff1a33e8a..495e2351e 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -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; } -- 2.11.0