thomascube
2006-02-22 745b1466fc76d5ded589e2469328086002430c1c
program/include/rcube_imap.inc
@@ -70,7 +70,7 @@
   */
  function __construct($db_conn)
    {
    $this->db = $db_conn;
    $this->db = $db_conn;
    }
@@ -376,14 +376,28 @@
    }
  // get message count for a specific mailbox; acceptes modes are: ALL, UNSEEN, RECENT
  /**
   * Get message count for a specific mailbox
   *
   * @param   string   Mailbox/folder name
   * @param   string   Mode for count [ALL|UNSEEN|RECENT]
   * @param   boolean  Force reading from server and update cache
   * @return  number   Number of messages
   * @access  public
   */
  function messagecount($mbox='', $mode='ALL', $force=FALSE)
    {
    $mailbox = $mbox ? $this->_mod_mailbox($mbox) : $this->mailbox;
    return $this->_messagecount($mailbox, $mode, $force);
    }
  // private method for getting nr of mesages
  /**
   * Private method for getting nr of messages
   *
   * @access  private
   * @see     rcube_imap::messagecount
   */
  function _messagecount($mailbox='', $mode='ALL', $force=FALSE)
    {
    $a_mailbox_cache = FALSE;
@@ -430,7 +444,7 @@
        $count = iil_C_CountMessages($this->conn, $mailbox);
      }
    if (is_array($a_mailbox_cache[$mailbox]))
    if (!is_array($a_mailbox_cache[$mailbox]))
      $a_mailbox_cache[$mailbox] = array();
      
    $a_mailbox_cache[$mailbox][$mode] = (int)$count;
@@ -442,8 +456,17 @@
    }
  // public method for listing headers
  // convert mailbox name with root dir first
  /**
   * Public method for listing headers
   * convert mailbox name with root dir first
   *
   * @param   string   Mailbox/folder name
   * @param   number   Current page to list
   * @param   string   Header field to sort by
   * @param   string   Sort order [ASC|DESC]
   * @return  array    Indexed array with message header objects
   * @access  public
   */
  function list_headers($mbox='', $page=NULL, $sort_field=NULL, $sort_order=NULL)
    {
    $mailbox = $mbox ? $this->_mod_mailbox($mbox) : $this->mailbox;
@@ -451,7 +474,12 @@
    }
  // private method for listing message header
  /**
   * Private method for listing message header
   *
   * @access  private
   * @see     rcube_imap::list_headers
   */
  function _list_headers($mailbox='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $recursive=FALSE)
    {
    if (!strlen($mailbox))
@@ -629,7 +657,7 @@
    // cache is OK
    if ($cache_status>0)
      {
      $a_index = $this->get_message_cache_index($cache_key, FALSE, $this->sort_field);
      $a_index = $this->get_message_cache_index($cache_key, TRUE, $this->sort_field, $this->sort_order);
      return array_values($a_index);
      }
@@ -738,7 +766,7 @@
    $mailbox = $mbox ? $this->_mod_mailbox($mbox) : $this->mailbox;
    // get cached headers
    if ($headers = $this->get_cached_message($mailbox.'.msg', $uid))
    if ($is_uid && ($headers = $this->get_cached_message($mailbox.'.msg', $id)))
      return $headers;
    $msg_id = $is_uid ? $this->_uid2id($id) : $id;
@@ -837,7 +865,7 @@
    {
    $mailbox = $this->_mod_mailbox($mbox);
    // make shure mailbox exists
    // make sure mailbox exists
    if (in_array($mailbox, $this->_list_mailboxes()))
      $saved = iil_C_Append($this->conn, $mailbox, $message);
@@ -857,10 +885,15 @@
    $to_mbox = $this->_mod_mailbox($to_mbox);
    $from_mbox = $from_mbox ? $this->_mod_mailbox($from_mbox) : $this->mailbox;
    // make shure mailbox exists
    // make sure mailbox exists
    if (!in_array($to_mbox, $this->_list_mailboxes()))
      return FALSE;
      {
      if (in_array(strtolower($to_mbox), $this->default_folders))
        $this->create_mailbox($to_mbox, TRUE);
      else
        return FALSE;
      }
    // convert the list of uids to array
    $a_uids = is_string($uids) ? explode(',', $uids) : (is_array($uids) ? $uids : NULL);
    
@@ -958,8 +991,18 @@
    
    if ($msg_count>0)
      {
      $this->clear_message_cache($mailbox.'.msg');
      return iil_C_ClearFolder($this->conn, $mailbox);
      $cleared = iil_C_ClearFolder($this->conn, $mailbox);
      // make sure the message count cache is cleared as well
      if ($cleared)
        {
        $this->clear_message_cache($mailbox.'.msg');
        $a_mailbox_cache = $this->get_cache('messagecount');
        unset($a_mailbox_cache[$mailbox]);
        $this->update_cache('messagecount', $a_mailbox_cache);
        }
      return $cleared;
      }
    else
      return 0;
@@ -1016,6 +1059,22 @@
    // filter folders and sort them
    $sa_unsubscribed = $this->_sort_mailbox_list($a_folders);
    return $sa_unsubscribed;
    }
  /**
   * Get quota
   * added by Nuny
   */
  function get_quota()
    {
    if ($this->get_capability('QUOTA'))
      {
      $result = iil_C_GetQuota($this->conn);
      return sprintf("%.2fMB / %.2fMB (%.0f%%)", $result["used"] / 1000.0, $result["total"] / 1000.0, $result["percent"]);
      }
    else
      return 'unknown';
    }
@@ -1382,7 +1441,7 @@
    }
   
  function get_message_cache_index($key, $force=FALSE, $sort_col='idx')
  function get_message_cache_index($key, $force=FALSE, $sort_col='idx', $sort_order='ASC')
    {
    static $sa_message_index = array();
    
@@ -1395,7 +1454,7 @@
       FROM ".get_table_name('messages')."
       WHERE  user_id=?
       AND    cache_key=?
       ORDER BY ".$sort_col." ASC",
       ORDER BY ".$this->db->quote_identifier($sort_col)." ".$sort_order,
      $_SESSION['user_id'],
      $key);
@@ -1413,16 +1472,16 @@
    $this->db->query(
      "INSERT INTO ".get_table_name('messages')."
       (user_id, del, cache_key, idx, uid, subject, ".$this->db->quoteIdentifier('from').", ".$this->db->quoteIdentifier('to').", cc, date, size, headers)
       VALUES (?, 0, ?, ?, ?, ?, ?, ?, ?, ".$this->db->fromunixtime($headers->timestamp).", ?, ?)",
       (user_id, del, cache_key, created, idx, uid, subject, ".$this->db->quoteIdentifier('from').", ".$this->db->quoteIdentifier('to').", cc, date, size, headers)
       VALUES (?, 0, ?, now(), ?, ?, ?, ?, ?, ?, ".$this->db->fromunixtime($headers->timestamp).", ?, ?)",
      $_SESSION['user_id'],
      $key,
      $index,
      $headers->uid,
      substr($this->decode_header($headers->subject, TRUE), 0, 128),
      substr($this->decode_header($headers->from, TRUE), 0, 128),
      substr($this->decode_header($headers->to, TRUE), 0, 128),
      substr($this->decode_header($headers->cc, TRUE), 0, 128),
      (string)substr($this->decode_header($headers->subject, TRUE), 0, 128),
      (string)substr($this->decode_header($headers->from, TRUE), 0, 128),
      (string)substr($this->decode_header($headers->to, TRUE), 0, 128),
      (string)substr($this->decode_header($headers->cc, TRUE), 0, 128),
      (int)$headers->size,
      serialize($headers));
    }
@@ -1548,10 +1607,10 @@
        $rest = quoted_printable_decode($rest);
        }
      return decode_specialchars($rest, $a[0]);
      return rcube_charset_convert($rest, $a[0]);
      }
    else
      return $str;    //we dont' know what to do with this
      return $str;    // we dont' know what to do with this
    }
@@ -1599,7 +1658,7 @@
  function charset_decode($body, $ctype_param)
    {
    if (is_array($ctype_param) && !empty($ctype_param['charset']))
      return decode_specialchars($body, $ctype_param['charset']);
      return rcube_charset_convert($body, $ctype_param['charset']);
    return $body;
    }
@@ -1877,4 +1936,4 @@
  return trim($output);
  }
?>
?>