/** * 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 */ 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 mailbox * * @param string $mbox_name Mailbox to rename * @param string $new_name New mailbox name * * @return boolean True on success */ function rename_mailbox($mbox_name, $new_name) { $result = false; // make absolute path $mailbox = $this->mod_mailbox($mbox_name); $abs_name = $this->mod_mailbox($new_name); $delm = $this->get_hierarchy_delimiter(); // get list of subscribed folders if (strpos($mailbox, '%') === false && strpos($mailbox, '*') === false) { $a_subscribed = $this->_list_mailboxes('', $mbox_name . $delm . '*'); $subscribed = $this->mailbox_exists($mbox_name, true); } else { $a_subscribed = $this->_list_mailboxes(); $subscribed = in_array($mailbox, $a_subscribed); } if (strlen($abs_name)) { $result = $this->conn->renameFolder($mailbox, $abs_name); } if ($result) { // unsubscribe the old folder, subscribe the new one if ($subscribed) { $this->conn->unsubscribe($mailbox); $this->conn->subscribe($abs_name); } // check if mailbox children are subscribed foreach ($a_subscribed as $c_subscribed) { if (preg_match('/^' . preg_quote($mailbox . $delm, '/') . '/', $c_subscribed)) { $this->conn->unsubscribe($c_subscribed); $this->conn->subscribe(preg_replace('/^' . preg_quote($mailbox, '/') . '/', $abs_name, $c_subscribed)); } } // clear cache $this->clear_message_cache($mailbox . '.msg'); $this->clear_cache('mailboxes'); } return $result; }