| | |
| | | * @param string Mailbox/folder name |
| | | * @param string Mode for count [ALL|THREADS|UNSEEN|RECENT] |
| | | * @param boolean Force reading from server and update cache |
| | | * @param boolean Enables MAXUIDs checking |
| | | * @param boolean Enables storing folder status info (max UID/count), |
| | | * required for mailbox_status() |
| | | * @return int Number of messages |
| | | * @access public |
| | | */ |
| | | function messagecount($mbox_name='', $mode='ALL', $force=false, $maxuid=true) |
| | | function messagecount($mbox_name='', $mode='ALL', $force=false, $status=true) |
| | | { |
| | | $mailbox = $mbox_name ? $this->mod_mailbox($mbox_name) : $this->mailbox; |
| | | return $this->_messagecount($mailbox, $mode, $force, $maxuid); |
| | | return $this->_messagecount($mailbox, $mode, $force, $status); |
| | | } |
| | | |
| | | |
| | |
| | | * @access private |
| | | * @see rcube_imap::messagecount() |
| | | */ |
| | | private function _messagecount($mailbox='', $mode='ALL', $force=false, $maxuid=true) |
| | | private function _messagecount($mailbox='', $mode='ALL', $force=false, $status=true) |
| | | { |
| | | $mode = strtoupper($mode); |
| | | |
| | |
| | | |
| | | if ($mode == 'THREADS') { |
| | | $count = $this->_threadcount($mailbox, $msg_count); |
| | | if ($maxuid) |
| | | $_SESSION['maxuid'][$mailbox] = $msg_count ? $this->_id2uid($msg_count, $mailbox) : 0; |
| | | if ($status) { |
| | | $this->set_folder_stats($mailbox, 'cnt', $msg_count); |
| | | $this->set_folder_stats($mailbox, 'maxuid', $msg_count ? $this->_id2uid($msg_count, $mailbox) : 0); |
| | | } |
| | | } |
| | | // RECENT count is fetched a bit different |
| | | else if ($mode == 'RECENT') { |
| | |
| | | |
| | | $count = is_array($index) ? count($index) : 0; |
| | | |
| | | if ($mode == 'ALL' && $maxuid) |
| | | $_SESSION['maxuid'][$mailbox] = $index ? $this->_id2uid(max($index), $mailbox) : 0; |
| | | if ($mode == 'ALL' && $status) { |
| | | $this->set_folder_stats($mailbox, 'cnt', $count); |
| | | $this->set_folder_stats($mailbox, 'maxuid', $index ? $this->_id2uid(max($index), $mailbox) : 0); |
| | | } |
| | | } |
| | | else { |
| | | if ($mode == 'UNSEEN') |
| | | $count = $this->conn->countUnseen($mailbox); |
| | | else { |
| | | $count = $this->conn->countMessages($mailbox); |
| | | if ($maxuid) |
| | | $_SESSION['maxuid'][$mailbox] = $count ? $this->_id2uid($count, $mailbox) : 0; |
| | | if ($status) { |
| | | $this->set_folder_stats($mailbox,'cnt', $count); |
| | | $this->set_folder_stats($mailbox, 'maxuid', $count ? $this->_id2uid($count, $mailbox) : 0); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | return count($a_msg_headers); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Fetches IDS of pseudo recent messages. |
| | | * Returns current status of mailbox |
| | | * |
| | | * We compare the maximum UID to determine the number of |
| | | * new messages because the RECENT flag is not reliable. |
| | | * |
| | | * @param string Mailbox/folder name |
| | | * @return array List of recent message UIDs |
| | | * @param string Mailbox/folder name |
| | | * @return int Folder status |
| | | */ |
| | | function recent_uids($mbox_name = null, $nofetch = false) |
| | | function mailbox_status($mbox_name = null) |
| | | { |
| | | $mailbox = $mbox_name ? $this->mod_mailbox($mbox_name) : $this->mailbox; |
| | | $old_maxuid = intval($_SESSION['maxuid'][$mailbox]); |
| | | |
| | | // refresh message count -> will update $_SESSION['maxuid'][$mailbox] |
| | | $old = $this->get_folder_stats($mailbox); |
| | | |
| | | // refresh message count -> will update |
| | | $this->_messagecount($mailbox, 'ALL', true); |
| | | |
| | | if ($_SESSION['maxuid'][$mailbox] > $old_maxuid) { |
| | | $maxuid = max(1, $old_maxuid+1); |
| | | return array_values((array)$this->conn->fetchHeaderIndex( |
| | | $mailbox, "$maxuid:*", 'UID', $this->skip_deleted, true)); |
| | | } |
| | | |
| | | return array(); |
| | | |
| | | $result = 0; |
| | | $new = $this->get_folder_stats($mailbox); |
| | | |
| | | // got new messages |
| | | if ($new['maxuid'] > $old['maxuid']) |
| | | $result += 1; |
| | | // some messages has been deleted |
| | | if ($new['cnt'] < $old['cnt']) |
| | | $result += 2; |
| | | |
| | | // @TODO: optional checking for messages flags changes (?) |
| | | // @TODO: UIDVALIDITY checking |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Stores folder statistic data in session |
| | | * @TODO: move to separate DB table (cache?) |
| | | * |
| | | * @param string Mailbox name |
| | | * @param string Data name |
| | | * @param mixed Data value |
| | | */ |
| | | private function set_folder_stats($mbox_name, $name, $data) |
| | | { |
| | | $_SESSION['folders'][$mbox_name][$name] = $data; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Gets folder statistic data |
| | | * |
| | | * @param string Mailbox name |
| | | * @return array Stats data |
| | | */ |
| | | private function get_folder_stats($mbox_name) |
| | | { |
| | | if ($_SESSION['folders'][$mbox_name]) |
| | | return (array) $_SESSION['folders'][$mbox_name]; |
| | | else |
| | | return array(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return sorted array of message IDs (not UIDs) |
| | | * |
| | |
| | | { |
| | | if (!empty($this->search_string)) |
| | | $this->search_set = $this->search('', $this->search_string, $this->search_charset, |
| | | $this->search_sort_field, $this->search_threads); |
| | | |
| | | $this->search_sort_field, $this->search_threads); |
| | | |
| | | return $this->get_search_set(); |
| | | } |
| | | |
| | |
| | | if ($headers->uid && $headers->id) |
| | | $this->uid_id_map[$mailbox][$headers->uid] = $headers->id; |
| | | |
| | | $this->add_message_cache($mailbox.'.msg', $headers->id, $headers, NULL, true); |
| | | $this->add_message_cache($mailbox.'.msg', $headers->id, $headers, NULL); |
| | | } |
| | | |
| | | return $headers; |
| | |
| | | $a_out = array(); |
| | | $a_mboxes = $this->_list_mailboxes($root, $filter); |
| | | |
| | | foreach ($a_mboxes as $mbox_row) { |
| | | $name = $this->mod_mailbox($mbox_row, 'out'); |
| | | if (strlen($name)) |
| | | foreach ($a_mboxes as $idx => $mbox_row) { |
| | | if ($name = $this->mod_mailbox($mbox_row, 'out')) |
| | | $a_out[] = $name; |
| | | unset($a_mboxes[$idx]); |
| | | } |
| | | |
| | | // INBOX should always be available |
| | |
| | | $a_mboxes = $this->conn->listMailboxes($this->mod_mailbox($root), '*'); |
| | | |
| | | // modify names with root dir |
| | | foreach ($a_mboxes as $mbox_name) { |
| | | foreach ($a_mboxes as $idx => $mbox_name) { |
| | | if ($name = $this->mod_mailbox($mbox_name, 'out')) |
| | | $a_folders[] = $name; |
| | | unset($a_mboxes[$idx]); |
| | | } |
| | | |
| | | // INBOX should always be available |
| | | if (!in_array('INBOX', $a_folders)) |
| | | array_unshift($a_folders, 'INBOX'); |
| | | |
| | | // filter folders and sort them |
| | | $a_folders = $this->_sort_mailbox_list($a_folders); |
| | |
| | | foreach ($a_mboxes as $mbox_name) { |
| | | $mailbox = $this->mod_mailbox($mbox_name); |
| | | $sub_mboxes = $this->conn->listMailboxes($this->mod_mailbox(''), |
| | | $mbox_name . $this->delimiter . '*'); |
| | | $mbox_name . $this->delimiter . '*'); |
| | | |
| | | // unsubscribe mailbox before deleting |
| | | $this->conn->unsubscribe($mailbox); |
| | |
| | | if ($mbox_name == 'INBOX') |
| | | return true; |
| | | |
| | | $key = $subscription ? 'subscribed' : 'existing'; |
| | | if (is_array($this->icache[$key]) && in_array($mbox_name, $this->icache[$key])) |
| | | return true; |
| | | |
| | | if ($subscription) { |
| | | if ($a_folders = $this->conn->listSubscribed($this->mod_mailbox(''), $mbox_name)) |
| | | return true; |
| | | $a_folders = $this->conn->listSubscribed($this->mod_mailbox(''), $mbox_name); |
| | | } |
| | | else { |
| | | $a_folders = $this->conn->listMailboxes($this->mod_mailbox(''), $mbox_name); |
| | | |
| | | if (is_array($a_folders) && in_array($this->mod_mailbox($mbox_name), $a_folders)) |
| | | } |
| | | |
| | | if (is_array($a_folders) && in_array($this->mod_mailbox($mbox_name), $a_folders)) { |
| | | $this->icache[$key][] = $mbox_name; |
| | | return true; |
| | | } |
| | | } |