From f0485adef1cd9b0d65bcbdd25bc546a2dff4095b Mon Sep 17 00:00:00 2001 From: alecpl <alec@alec.pl> Date: Wed, 28 Apr 2010 08:24:48 -0400 Subject: [PATCH] - Fix folder subscription checking (#1486684) - Fix INBOX appears (sometimes) twice in mailbox list (#1486672) --- program/include/rcube_imap.php | 61 +++++++++++++++++------------- 1 files changed, 35 insertions(+), 26 deletions(-) diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index 466c47a..f5b1728 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -26,7 +26,8 @@ * * @package Mail * @author Thomas Bruederli <roundcube@gmail.com> - * @version 1.6 + * @author Aleksander Machniak <alec@alec.pl> + * @version 2.0 */ class rcube_imap { @@ -91,7 +92,7 @@ */ function connect($host, $user, $pass, $port=143, $use_ssl=null) { - // check for Open-SSL support in PHP build + // check for OpenSSL support in PHP build if ($use_ssl && extension_loaded('openssl')) $this->options['ssl_mode'] = $use_ssl == 'imaps' ? 'ssl' : $use_ssl; else if ($use_ssl) { @@ -408,16 +409,17 @@ /** * Get message count for a specific mailbox * - * @param string Mailbox/folder name - * @param string Mode for count [ALL|THREADS|UNSEEN|RECENT] - * @param boolean Force reading from server and update cache - * @return int Number of messages - * @access public + * @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 + * @return int Number of messages + * @access public */ - function messagecount($mbox_name='', $mode='ALL', $force=false) + function messagecount($mbox_name='', $mode='ALL', $force=false, $maxuid=true) { $mailbox = $mbox_name ? $this->mod_mailbox($mbox_name) : $this->mailbox; - return $this->_messagecount($mailbox, $mode, $force); + return $this->_messagecount($mailbox, $mode, $force, $maxuid); } @@ -427,7 +429,7 @@ * @access private * @see rcube_imap::messagecount() */ - private function _messagecount($mailbox='', $mode='ALL', $force=false) + private function _messagecount($mailbox='', $mode='ALL', $force=false, $maxuid=true) { $mode = strtoupper($mode); @@ -453,7 +455,8 @@ if ($mode == 'THREADS') { $count = $this->_threadcount($mailbox, $msg_count); - $_SESSION['maxuid'][$mailbox] = $msg_count ? $this->_id2uid($msg_count) : 0; + if ($maxuid) + $_SESSION['maxuid'][$mailbox] = $msg_count ? $this->_id2uid($msg_count, $mailbox) : 0; } // RECENT count is fetched a bit different else if ($mode == 'RECENT') { @@ -477,15 +480,16 @@ $count = is_array($index) ? count($index) : 0; - if ($mode == 'ALL') - $_SESSION['maxuid'][$mailbox] = $index ? $this->_id2uid(max($index)) : 0; + if ($mode == 'ALL' && $maxuid) + $_SESSION['maxuid'][$mailbox] = $index ? $this->_id2uid(max($index), $mailbox) : 0; } else { if ($mode == 'UNSEEN') $count = $this->conn->countUnseen($mailbox); else { $count = $this->conn->countMessages($mailbox); - $_SESSION['maxuid'][$mailbox] = $count ? $this->_id2uid($count) : 0; + if ($maxuid) + $_SESSION['maxuid'][$mailbox] = $count ? $this->_id2uid($count, $mailbox) : 0; } } @@ -1571,7 +1575,7 @@ function get_headers($id, $mbox_name=NULL, $is_uid=true, $bodystr=false) { $mailbox = $mbox_name ? $this->mod_mailbox($mbox_name) : $this->mailbox; - $uid = $is_uid ? $id : $this->_id2uid($id); + $uid = $is_uid ? $id : $this->_id2uid($id, $mailbox); // get cached headers if ($uid && ($headers = &$this->get_cached_message($mailbox.'.msg', $uid))) @@ -2478,10 +2482,10 @@ $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 @@ -2550,10 +2554,15 @@ $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); @@ -2704,7 +2713,7 @@ 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); @@ -2766,13 +2775,13 @@ 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_mbox); - - if (is_array($a_folders) && in_array($this->mod_mailbox($mbox_name), $a_folders)) + $a_folders = $this->conn->listMailboxes($this->mod_mailbox(''), $mbox_name); + } + + if (is_array($a_folders) && in_array($this->mod_mailbox($mbox_name), $a_folders)) { return true; } } @@ -3146,7 +3155,7 @@ if (!$this->caching_enabled) return; - // check for an existing record (probly headers are cached but structure not) + // check for an existing record (probably headers are cached but structure not) if (!$force) { $sql_result = $this->db->query( "SELECT message_id". -- Gitblit v1.9.1