thomascube
2009-04-19 cc97ea0559af1a92a54dbcdf738ee4d95e67d3ff
program/include/rcube_imap.php
@@ -55,6 +55,7 @@
  var $default_charset = 'ISO-8859-1';
  var $default_folders = array('INBOX');
  var $default_folders_lc = array('inbox');
  var $fetch_add_headers = '';
  var $cache = array();
  var $cache_keys = array();  
  var $cache_changes = array();
@@ -97,7 +98,7 @@
    global $ICL_SSL, $ICL_PORT, $IMAP_USE_INTERNAL_DATE;
    
    // check for Open-SSL support in PHP build
    if ($use_ssl && in_array('openssl', get_loaded_extensions()))
    if ($use_ssl && extension_loaded('openssl'))
      $ICL_SSL = $use_ssl == 'imaps' ? 'ssl' : $use_ssl;
    else if ($use_ssl)
      {
@@ -428,8 +429,16 @@
    if (is_array($a_mboxes))
      return $a_mboxes;
    // retrieve list of folders from IMAP server
    $a_folders = iil_C_ListSubscribed($this->conn, $this->_mod_mailbox($root), $filter);
    // Give plugins a chance to provide a list of mailboxes
    $data = rcmail::get_instance()->plugins->exec_hook('list_mailboxes',array('root'=>$root,'filter'=>$filter));
    if (isset($data['folders'])) {
        $a_folders = $data['folders'];
    }
    else{
        // retrieve list of folders from IMAP server
        $a_folders = iil_C_ListSubscribed($this->conn, $this->_mod_mailbox($root), $filter);
    }
    
    if (!is_array($a_folders) || !sizeof($a_folders))
      $a_folders = array();
@@ -775,7 +784,7 @@
    $cache_index = $this->get_message_cache_index($cache_key);
    
    // fetch reuested headers from server
    $a_header_index = iil_C_FetchHeaders($this->conn, $mailbox, $msgs);
    $a_header_index = iil_C_FetchHeaders($this->conn, $mailbox, $msgs, false, $this->fetch_add_headers);
    $deleted_count = 0;
    
    if (!empty($a_header_index))
@@ -829,14 +838,14 @@
        if ($this->sort_field && $this->search_sort_field != $this->sort_field)
          $this->search('', $this->search_string, $this->search_charset, $this->sort_field);
   if ($this->sort_order == 'DESC')
        if ($this->sort_order == 'DESC')
          $this->cache[$key] = array_reverse($this->search_set);
   else
     $this->cache[$key] = $this->search_set;
        else
          $this->cache[$key] = $this->search_set;
        }
      else
        {
   $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, join(',', $this->search_set), $this->sort_field);
        $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, join(',', $this->search_set), $this->sort_field, false);
        if ($this->sort_order=="ASC")
          asort($a_index);
@@ -923,7 +932,7 @@
        
      // fetch complete headers and add to cache
      $headers = iil_C_FetchHeader($this->conn, $mailbox, $id);
      $headers = iil_C_FetchHeader($this->conn, $mailbox, $id, false, $this->fetch_add_headers);
      $this->add_message_cache($cache_key, $headers->id, $headers);
      }
@@ -955,11 +964,11 @@
    $results = $this->_search_index($mailbox, $str, $charset, $sort_field);
    // try search with ISO charset (should be supported by server)
    // try search with US-ASCII charset (should be supported by server)
    // only if UTF-8 search is not supported
    if (empty($results) && !is_array($results) && !empty($charset) && $charset!='ISO-8859-1')
    if (empty($results) && !is_array($results) && !empty($charset) && $charset!='US-ASCII')
      {
   // convert strings to ISO-8859-1
   // convert strings to US_ASCII
        if(preg_match_all('/\{([0-9]+)\}\r\n/', $str, $matches, PREG_OFFSET_CAPTURE))
     {
     $last = 0; $res = '';
@@ -967,7 +976,8 @@
       {
       $string_offset = $m[1] + strlen($m[0]) + 4; // {}\r\n
       $string = substr($str, $string_offset - 1, $m[0]);
       $string = rcube_charset_convert($string, $charset, 'ISO-8859-1');
       $string = rcube_charset_convert($string, $charset, 'US-ASCII');
       if (!$string) continue;
       $res .= sprintf("%s{%d}\r\n%s", substr($str, $last, $m[1] - $last - 1), strlen($string), $string);
       $last = $m[0] + $string_offset - 1;
       }
@@ -977,7 +987,7 @@
   else // strings for conversion not found
     $res = $str;
     
   $results = $this->search($mbox_name, $res, 'ISO-8859-1', $sort_field);
   $results = $this->search($mbox_name, $res, 'US-ASCII', $sort_field);
      }
    $this->set_search_set($str, $results, $charset, $sort_field);
@@ -1061,7 +1071,7 @@
    if ($uid && ($headers = &$this->get_cached_message($mailbox.'.msg', $uid)))
      return $headers;
    $headers = iil_C_FetchHeader($this->conn, $mailbox, $id, $is_uid, $bodystr);
    $headers = iil_C_FetchHeader($this->conn, $mailbox, $id, $is_uid, $bodystr, $this->fetch_add_headers);
    // write headers cache
    if ($headers)
@@ -2226,7 +2236,7 @@
    if ($cache_count==$msg_count)
      {
      // get highest index
      $header = iil_C_FetchHeader($this->conn, $mailbox, "$msg_count");
      $header = iil_C_FetchHeader($this->conn, $mailbox, "$msg_count", false, $this->fetch_add_headers);
      $cache_uid = array_pop($cache_index);
      
      // uids of highest message matches -> cache seems OK
@@ -2276,7 +2286,7 @@
        
        // featch headers if unserialize failed
        if (empty($this->cache[$cache_key][$uid]))
          $this->cache[$cache_key][$uid] = iil_C_FetchHeader($this->conn, preg_replace('/.msg$/', '', $key), $uid, true);
          $this->cache[$cache_key][$uid] = iil_C_FetchHeader($this->conn, preg_replace('/.msg$/', '', $key), $uid, true, $this->fetch_add_headers);
        }
      }