alecpl
2010-04-23 d824acaf11b9cc0d196488ef3c9bc03bee41f948
program/include/rcube_imap.php
@@ -21,10 +21,6 @@
*/
require_once('lib/mime.inc');
require_once('lib/tnef_decoder.inc');
/**
 * Interface class for accessing an IMAP server
 *
@@ -135,6 +131,8 @@
                $this->set_rootdir($this->conn->rootdir);
            if (empty($this->delimiter))
               $this->get_hierarchy_delimiter();
            return true;
        }
        // write error log
        else if ($this->conn->error) {
@@ -144,7 +142,7 @@
                'message' => $this->conn->error), true, false);
        }
        return $this->conn ? true : false;
        return false;
    }
@@ -410,16 +408,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);
    }
@@ -429,7 +428,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);
@@ -455,7 +454,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') {
@@ -479,15 +479,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;
            }
        }
@@ -1412,6 +1413,27 @@
        return $a_messages;
    }
    
    /**
     * Direct (real and simple) SEARCH request to IMAP server,
     * without result sorting and caching
     *
     * @param  string  Mailbox name to search in
     * @param  string  Search string
     * @param  boolean True if UIDs should be returned
     * @return array   Search results as list of message IDs or UIDs
     * @access public
     */
    function search_once($mbox_name='', $str=NULL, $ret_uid=false)
    {
        if (!$str)
            return false;
        $mailbox = $mbox_name ? $this->mod_mailbox($mbox_name) : $this->mailbox;
        return $this->conn->search($mailbox, $str, $ret_uid);
    }
  
    /**
     * Sort thread
@@ -1552,7 +1574,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)))
@@ -1591,9 +1613,10 @@
            return $headers->structure;
        }
        if (!$structure_str)
        if (!$structure_str) {
            $structure_str = $this->conn->fetchStructureString($this->mailbox, $uid, true);
        $structure = iml_GetRawStructureArray($structure_str);
        }
        $structure = rcube_mime_struct::parseStructure($structure_str);
        $struct = false;
        // parse structure and add headers
@@ -1943,16 +1966,16 @@
        // get part encoding if not provided
        if (!is_object($o_part)) {
            $structure_str = $this->conn->fetchStructureString($this->mailbox, $uid, true); 
            $structure = iml_GetRawStructureArray($structure_str);
            $structure = new rcube_mime_struct();
            // error or message not found
            if (empty($structure))
            if (!$structure->loadStructure($structure_str)) {
                return false;
            }
            $part_type = iml_GetPartTypeCode($structure, $part);
            $o_part = new rcube_message_part;
            $o_part->ctype_primary = $part_type==0 ? 'text' : ($part_type==2 ? 'message' : 'other');
            $o_part->encoding = strtolower(iml_GetPartEncodingString($structure, $part));
            $o_part->charset = iml_GetPartCharset($structure, $part);
            $o_part->ctype_primary = strtolower($structure->getPartType($part));
            $o_part->encoding      = strtolower($structure->getPartEncoding($part));
            $o_part->charset       = $structure->getPartCharset($part);
        }
      
        // TODO: Add caching for message parts
@@ -2521,24 +2544,23 @@
     */
    function list_unsubscribed($root='')
    {
        static $sa_unsubscribed;
        static $a_folders;
    
        if (is_array($sa_unsubscribed))
            return $sa_unsubscribed;
        if (is_array($a_folders))
            return $a_folders;
      
        // retrieve list of folders from IMAP server
        $a_mboxes = $this->conn->listMailboxes($this->mod_mailbox($root), '*');
        // modify names with root dir
        foreach ($a_mboxes as $mbox_name) {
            $name = $this->mod_mailbox($mbox_name, 'out');
            if (strlen($name))
            if ($name = $this->mod_mailbox($mbox_name, 'out'))
                $a_folders[] = $name;
        }
        // filter folders and sort them
        $sa_unsubscribed = $this->_sort_mailbox_list($a_folders);
        return $sa_unsubscribed;
        $a_folders = $this->_sort_mailbox_list($a_folders);
        return $a_folders;
    }
@@ -2751,7 +2773,7 @@
                    return true;
            }
            else {
                $a_folders = $this->conn->listMailboxes($this->mod_mailbox(''), $mbox_mbox);
                $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;
@@ -3308,6 +3330,8 @@
        if (!isset($part->body))
            $part->body = $this->get_message_part($uid, $part->mime_id, $part);
        require_once('lib/tnef_decoder.inc');
        $pid = 0;
        $tnef_parts = array();
        $tnef_arr = tnef_decode($part->body);
@@ -3511,7 +3535,7 @@
            if (($p = array_search($folder, $this->default_folders)) !== false && !$a_defaults[$p])
                $a_defaults[$p] = $folder;
            else
                $folders[$folder] = mb_strtolower(rcube_charset_convert($folder, 'UTF7-IMAP'));
                $folders[$folder] = rcube_charset_convert($folder, 'UTF7-IMAP');
        }
        // sort folders and place defaults on the top