alecpl
2008-12-12 2b5c123aadfa50f09a60b3d05c240932f9e5907a
program/include/rcube_imap.php
@@ -107,7 +107,17 @@
    $ICL_PORT = $port;
    $IMAP_USE_INTERNAL_DATE = false;
    $this->conn = iil_Connect($host, $user, $pass, array('imap' => $auth_type ? $auth_type : 'check'));
    // set connection options
    $options['imap'] = $auth_type ? $auth_type : 'check';
    // Setting root and delimiter before iil_Connect can save time detecting them
    // using NAMESPACE and LIST
    if (is_string($imap_root = rcmail::get_instance()->config->get('imap_root')))
        $options['rootdir'] = $imap_root;
    if($imap_delimiter = rcmail::get_instance()->config->get('imap_delimiter'))
        $options['delimiter'] = $imap_delimiter;
    $this->conn = iil_Connect($host, $user, $pass, $options);
    $this->host = $host;
    $this->user = $user;
    $this->pass = $pass;
@@ -294,7 +304,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;
    }
@@ -673,11 +683,12 @@
      return array_values($a_msg_headers);
      }
    else { // SEARCH searching result, need sorting
      if ($cnt > $this->pagesize * 2) {
      $cnt = count($msgs);
      if ($cnt > 300 && $cnt > $this->page_size) { // experimantal value for best result
        // use memory less expensive (and quick) method for big result set
   $a_index = $this->message_index($mailbox, $this->sort_field, $this->sort_order);
        // get messages uids for one page...
        $msgs = array_slice(array_keys($a_index), $start_msg, min(count($msgs)-$start_msg, $this->page_size));
        $msgs = array_slice(array_keys($a_index), $start_msg, min($cnt-$start_msg, $this->page_size));
   // ...and fetch headers
        $this->_fetch_headers($mailbox, join(',', $msgs), $a_msg_headers, NULL);
@@ -703,7 +714,7 @@
        $a_msg_headers = iil_SortHeaders($a_msg_headers, $this->sort_field, $this->sort_order);
      
        // only return the requested part of the set
        return array_slice(array_values($a_msg_headers), $start_msg, min(count($msgs)-$start_msg, $this->page_size));
        return array_slice(array_values($a_msg_headers), $start_msg, min($cnt-$start_msg, $this->page_size));
        }
      }
    }
@@ -810,7 +821,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'))
        {
@@ -831,7 +842,7 @@
        else if ($this->sort_order=="DESC")
          arsort($a_index);
        $this->cache[$key] = $a_index;
        $this->cache[$key] = array_keys($a_index);
   }
    }
@@ -847,9 +858,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);
@@ -869,7 +879,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];
@@ -984,9 +994,8 @@
   */
  function _search_index($mailbox, $criteria='ALL', $charset=NULL, $sort_field=NULL)
    {
    if ($this->get_capability('sort'))
    if ($sort_field && $this->get_capability('sort'))
      {
      $sort_field = $sort_field ? $sort_field : $this->sort_field;
      $charset = $charset ? $charset : $this->default_charset;
      $a_messages = iil_C_Sort($this->conn, $mailbox, $sort_field, $criteria, FALSE, $charset);
      }
@@ -1365,6 +1374,8 @@
      
    // TODO: Add caching for message parts
    if (!$part) $part = 'TEXT';
    if ($print)
      {
      $mode = $o_part->encoding == 'base64' ? 3 : ($o_part->encoding == 'quoted-printable' ? 1 : 2);
@@ -1436,10 +1447,7 @@
    if (!($msg_id = $this->_uid2id($uid)))
      return FALSE;
    $body = iil_C_FetchPartHeader($this->conn, $this->mailbox, $msg_id, NULL);
    $body .= iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, NULL, 1);
    return $body;
    return iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id);
    }
@@ -1470,8 +1478,6 @@
    if (!($msg_id = $this->_uid2id($uid)))
      return FALSE;
    print iil_C_FetchPartHeader($this->conn, $this->mailbox, $msg_id, NULL);
    flush();
    iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, NULL, 2);
    }
@@ -2149,8 +2155,7 @@
      {
      $this->db->query(
        "UPDATE ".get_table_name('cache')."
         SET    created=".$this->db->now().",
                data=?
         SET    created=". $this->db->now().", data=?
         WHERE  user_id=?
         AND    cache_key=?",
        $data,
@@ -2500,12 +2505,13 @@
  /**
   * Decode a mime-encoded string to internal charset
   *
   * @param string  Header value
   * @param string  Fallback charset if none specified
   * @param string $input    Header value
   * @param string $fallback Fallback charset if none specified
   *
   * @return string Decoded string
   * @static
   */
  function decode_mime_string($input, $fallback=null)
  public static function decode_mime_string($input, $fallback=null)
    {
    // Initialize variable
    $out = '';
@@ -2714,32 +2720,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
   */