roundcubemail/program/lib/Roundcube/rcube_imap.php
public function rename_folder($folder, $new_name)
    {
        if (!strlen($new_name)) {
            return false;
        }

        if (!$this->check_connection()) {
            return false;
        }

        $delm = $this->get_hierarchy_delimiter();

        // get list of subscribed folders
        if ((strpos($folder, '%') === false) && (strpos($folder, '*') === false)) {
            $a_subscribed = $this->list_folders_subscribed('', $folder . $delm . '*');
            $subscribed   = $this->folder_exists($folder, true);
        }
        else {
            $a_subscribed = $this->list_folders_subscribed();
            $subscribed   = in_array($folder, $a_subscribed);
        }

        $result = $this->conn->renameFolder($folder, $new_name);

        if ($result) {
            // unsubscribe the old folder, subscribe the new one
            if ($subscribed) {
                $this->conn->unsubscribe($folder);
                $this->conn->subscribe($new_name);
            }

            // check if folder children are subscribed
            foreach ($a_subscribed as $c_subscribed) {
                if (strpos($c_subscribed, $folder.$delm) === 0) {
                    $this->conn->unsubscribe($c_subscribed);
                    $this->conn->subscribe(preg_replace('/^'.preg_quote($folder, '/').'/',
                        $new_name, $c_subscribed));

                    // clear cache
                    $this->clear_message_cache($c_subscribed);
                }
            }

            // clear cache
            $this->clear_message_cache($folder);
            $this->clear_cache('mailboxes', true);
        }

        return $result;
    }
public function rename_folder($folder, $new_name)
    {
        if (!strlen($new_name)) {
            return false;
        }

        if (!$this->check_connection()) {
            return false;
        }

        $delm = $this->get_hierarchy_delimiter();

        // get list of subscribed folders
        if ((strpos($folder, '%') === false) && (strpos($folder, '*') === false)) {
            $a_subscribed = $this->list_folders_subscribed('', $folder . $delm . '*');
            $subscribed   = $this->folder_exists($folder, true);
        }
        else {
            $a_subscribed = $this->list_folders_subscribed();
            $subscribed   = in_array($folder, $a_subscribed);
        }

        $result = $this->conn->renameFolder($folder, $new_name);

        if ($result) {
            // unsubscribe the old folder, subscribe the new one
            if ($subscribed) {
                $this->conn->unsubscribe($folder);
                $this->conn->subscribe($new_name);
            }

            // check if folder children are subscribed
            foreach ($a_subscribed as $c_subscribed) {
                if (strpos($c_subscribed, $folder.$delm) === 0) {
                    $this->conn->unsubscribe($c_subscribed);
                    $this->conn->subscribe(preg_replace('/^'.preg_quote($folder, '/').'/',
                        $new_name, $c_subscribed));

                    // clear cache
                    $this->clear_message_cache($c_subscribed);
                }
            }

            // clear cache
            $this->clear_message_cache($folder);
            $this->clear_cache('mailboxes', true);
        }

        return $result;
    }
public function rename_folder ( $ folder , $ new_name ) { if ( ! strlen ( $ new_name ) ) { return false ; } if ( ! $ this -> check_connection ( ) ) { return false ; } $ delm = $ this -> get_hierarchy_delimiter ( ) ; // get list of subscribed folders if ( ( strpos ( $ folder , '%' ) === false ) && ( strpos ( $ folder , '*' ) === false ) ) { $ a_subscribed = $ this -> list_folders_subscribed ( '' , $ folder . $ delm . '*' ) ; $ subscribed = $ this -> folder_exists ( $ folder , true ) ; } else { $ a_subscribed = $ this -> list_folders_subscribed ( ) ; $ subscribed = in_array ( $ folder , $ a_subscribed ) ; } $ result = $ this -> conn -> renameFolder ( $ folder , $ new_name ) ; if ( $ result ) { // unsubscribe the old folder, subscribe the new one if ( $ subscribed ) { $ this -> conn -> unsubscribe ( $ folder ) ; $ this -> conn -> subscribe ( $ new_name ) ; } // check if folder children are subscribed foreach ( $ a_subscribed as $ c_subscribed ) { if ( strpos ( $ c_subscribed , $ folder . $ delm ) === 0 ) { $ this -> conn -> unsubscribe ( $ c_subscribed ) ; $ this -> conn -> subscribe ( preg_replace ( '/^' . preg_quote ( $ folder , '/' ) . '/' , $ new_name , $ c_subscribed ) ) ; // clear cache $ this -> clear_message_cache ( $ c_subscribed ) ; } } // clear cache $ this -> clear_message_cache ( $ folder ) ; $ this -> clear_cache ( 'mailboxes' , true ) ; } return $ result ; }
Set a new name to an existing folder

@param string $folder   Folder to rename
@param string $new_name New folder name

@return boolean True on success
Set a new name to an existing folder