thomascube
2008-12-24 230f944bf62f141f47c021dbfe6cc3d07b74a76d
program/include/rcube_imap.php
@@ -66,6 +66,7 @@
  var $search_sort_field = '';  
  var $debug_level = 1;
  var $error_code = 0;
  var $options = array('imap' => 'check');
  /**
@@ -90,7 +91,7 @@
   * @return boolean  TRUE on success, FALSE on failure
   * @access public
   */
  function connect($host, $user, $pass, $port=143, $use_ssl=null, $auth_type=null)
  function connect($host, $user, $pass, $port=143, $use_ssl=null)
    {
    global $ICL_SSL, $ICL_PORT, $IMAP_USE_INTERNAL_DATE;
    
@@ -107,7 +108,7 @@
    $ICL_PORT = $port;
    $IMAP_USE_INTERNAL_DATE = false;
    $this->conn = iil_Connect($host, $user, $pass, array('imap' => $auth_type ? $auth_type : 'check'));
    $this->conn = iil_Connect($host, $user, $pass, $this->options);
    $this->host = $host;
    $this->user = $user;
    $this->pass = $pass;
@@ -172,6 +173,13 @@
      iil_C_Select($this->conn, $this->mailbox);
    }
  /**
   * Set options to be used in iil_Connect()
   */
  function set_options($opt)
  {
    $this->options = array_merge((array)$opt, $this->options);
  }
  /**
   * Set a root folder for the IMAP connection.
@@ -188,6 +196,7 @@
      $root = substr($root, 0, -1);
    $this->root_dir = $root;
    $this->options['rootdir'] = $root;
    
    if (empty($this->delimiter))
      $this->get_hierarchy_delimiter();
@@ -294,7 +303,7 @@
      $msgs = split(',', $msgs);
      
    $this->search_string = $str;
    $this->search_set = (array)$msgs;
    $this->search_set = $msgs;
    $this->search_charset = $charset;
    $this->search_sort_field = $sort_field;
    }
@@ -811,7 +820,7 @@
    // we have a saved search result. get index from there
    if (!isset($this->cache[$key]) && $this->search_string && $mailbox == $this->mailbox)
    {
      $this->cache[$key] = $a_msg_headers = array();
      $this->cache[$key] = array();
      
      if ($this->get_capability('sort'))
        {
@@ -832,7 +841,7 @@
        else if ($this->sort_order=="DESC")
          arsort($a_index);
        $this->cache[$key] = $a_index;
        $this->cache[$key] = array_keys($a_index);
   }
    }
@@ -848,9 +857,8 @@
    if ($cache_status>0)
      {
      $a_index = $this->get_message_cache_index($cache_key, TRUE, $this->sort_field, $this->sort_order);
      return array_values($a_index);
      return array_keys($a_index);
      }
    // fetch complete message index
    $msg_count = $this->_messagecount($mailbox);
@@ -870,7 +878,7 @@
      else if ($this->sort_order=="DESC")
        arsort($a_index);
        
      $this->cache[$key] = $a_index;
      $this->cache[$key] = array_keys($a_index);
      }
    return $this->cache[$key];
@@ -2146,11 +2154,10 @@
      {
      $this->db->query(
        "UPDATE ".get_table_name('cache')."
         SET    created=". $this->db->fromunixtime(time()).", data=?, session_id=?
         SET    created=". $this->db->now().", data=?
         WHERE  user_id=?
         AND    cache_key=?",
        $data,
   session_id(),
        $_SESSION['user_id'],
        $key);
      }
@@ -2159,12 +2166,11 @@
      {
      $this->db->query(
        "INSERT INTO ".get_table_name('cache')."
         (created, user_id, cache_key, data, session_id)
         VALUES (".$this->db->fromunixtime(time()).", ?, ?, ?, ?)",
         (created, user_id, cache_key, data)
         VALUES (".$this->db->now().", ?, ?, ?)",
        $_SESSION['user_id'],
        $key,
        $data,
   session_id());
        $data);
      }
    }
@@ -2374,7 +2380,7 @@
      $this->db->query(
        "INSERT INTO ".get_table_name('messages')."
         (user_id, del, cache_key, created, idx, uid, subject, ".$this->db->quoteIdentifier('from').", ".$this->db->quoteIdentifier('to').", cc, date, size, headers, structure)
         VALUES (?, 0, ?, ".$this->db->fromunixtime(time()).", ?, ?, ?, ?, ?, ?, ".$this->db->fromunixtime($headers->timestamp).", ?, ?, ?)",
         VALUES (?, 0, ?, ".$this->db->now().", ?, ?, ?, ?, ?, ?, ".$this->db->fromunixtime($headers->timestamp).", ?, ?, ?)",
        $_SESSION['user_id'],
        $key,
        $index,
@@ -2713,32 +2719,43 @@
        $folders[$folder] = rc_strtolower(rcube_charset_convert($folder, 'UTF-7'));
      }
    // sort folders and place defaults on the top
    asort($folders, SORT_LOCALE_STRING);
    ksort($a_defaults);
    $folders = array_merge($a_defaults, array_keys($folders));
    // finally we must rebuild the list to move 
    // subfolders of default folders to their place...
    // ...also do this for the rest of folders because
    // asort() is not properly sorting case sensitive names
    // set the type of folder name variable (#1485527)
    while (list($key, $folder) = each($folders)) {
      // set the type of folder name variable (#1485527)
      $a_out[] = (string) $folder;
      unset($folders[$key]);
      foreach ($folders as $idx => $f) {
   if (strpos($f, $folder.$delimiter) === 0) {
         $a_out[] = (string) $f;
     unset($folders[$idx]);
     }
        }
      reset($folders);
      $this->_rsort($folder, $delimiter, $folders, $a_out);
      }
    return $a_out;
    }
  /**
   * @access private
   */
  function _rsort($folder, $delimiter, &$list, &$out)
    {
      while (list($key, $name) = each($list)) {
   if (strpos($name, $folder.$delimiter) === 0) {
     // set the type of folder name variable (#1485527)
         $out[] = (string) $name;
     unset($list[$key]);
     $this->_rsort($name, $delimiter, $list, $out);
     }
        }
      reset($list);
    }
  /**
   * @access private
   */