/** * Subscribe/unsubscribe a list of folders and update local cache */ protected function change_subscription($folders, $mode) { $updated = false; if (!empty($folders)) { if (!$this->check_connection()) { return false; } foreach ((array)$folders as $i => $folder) { $folders[$i] = $folder; if ($mode == 'subscribe') { $updated = $this->conn->subscribe($folder); } else if ($mode == 'unsubscribe') { $updated = $this->conn->unsubscribe($folder); } } } // clear cached folders list(s) if ($updated) { $this->clear_cache('mailboxes', true); } return $updated; }
/** * Subscribe/unsubscribe a list of mailboxes and update local cache * @access private */ private function _change_subscription($a_mboxes, $mode) { $updated = false; if (is_array($a_mboxes)) { foreach ($a_mboxes as $i => $mbox_name) { $mailbox = $this->mod_mailbox($mbox_name); $a_mboxes[$i] = $mailbox; if ($mode == 'subscribe') { $updated = $this->conn->subscribe($mailbox); } else { if ($mode == 'unsubscribe') { $updated = $this->conn->unsubscribe($mailbox); } } } } // get cached mailbox list if ($updated) { $a_mailbox_cache = $this->get_cache('mailboxes'); if (!is_array($a_mailbox_cache)) { return $updated; } // modify cached list if ($mode == 'subscribe') { $a_mailbox_cache = array_merge($a_mailbox_cache, $a_mboxes); } else { if ($mode == 'unsubscribe') { $a_mailbox_cache = array_diff($a_mailbox_cache, $a_mboxes); } } // write mailboxlist to cache $this->update_cache('mailboxes', $this->_sort_mailbox_list($a_mailbox_cache)); } return $updated; }
/** * Subscribe/unsubscribe a list of mailboxes and update local cache * @access private */ private function _change_subscription($a_mboxes, $mode) { $updated = false; if (is_array($a_mboxes)) { foreach ($a_mboxes as $i => $mailbox) { $a_mboxes[$i] = $mailbox; if ($mode == 'subscribe') { $updated = $this->conn->subscribe($mailbox); } else { if ($mode == 'unsubscribe') { $updated = $this->conn->unsubscribe($mailbox); } } } } // clear cached mailbox list(s) if ($updated) { $this->clear_cache('mailboxes', true); } return $updated; }
/** * 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; }