alecpl
2009-01-28 5c771cb25e62494cba263097175d9b718acb8aba
program/include/rcube_imap.php
@@ -354,8 +354,9 @@
   */
  function check_permflag($flag)
    {
    $flagsmap = $GLOBALS['IMAP_FLAGS'];
    return (($imap_flag = $flagsmap[strtoupper($flag)]) && in_array_nocase($imap_flag, $this->conn->permanentflags));
    $flag = strtoupper($flag);
    $imap_flag = $GLOBALS['IMAP_FLAGS'][$flag];
    return (in_array_nocase($imap_flag, $this->conn->permanentflags));
    }
@@ -685,9 +686,9 @@
      $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);
   $a_index = $this->message_index('', $this->sort_field, $this->sort_order);
        // get messages uids for one page...
        $msgs = array_slice(array_keys($a_index), $start_msg, min($cnt-$start_msg, $this->page_size));
        $msgs = array_slice($a_index, $start_msg, min($cnt-$start_msg, $this->page_size));
   // ...and fetch headers
        $this->_fetch_headers($mailbox, join(',', $msgs), $a_msg_headers, NULL);
@@ -1504,36 +1505,34 @@
   *
   * @param mixed  Message UIDs as array or as comma-separated string
   * @param string Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT
   * @param boolean Simulate flagging (don't set flag on IMAP server)
   * @return boolean True on success, False on failure
   */
  function set_flag($uids, $flag, $fake=false)
  function set_flag($uids, $flag)
    {
    $flag = strtoupper($flag);
    $msg_ids = array();
    if (!is_array($uids))
      $uids = explode(',',$uids);
      
    if (!$fake || $this->caching_enabled)
      foreach ($uids as $uid) {
        $msg_ids[$uid] = $this->_uid2id($uid);
      }
    if (!$fake) {
      if ($flag=='UNDELETED')
        $result = iil_C_Undelete($this->conn, $this->mailbox, join(',', array_values($msg_ids)));
      else if ($flag=='UNSEEN')
        $result = iil_C_Unseen($this->conn, $this->mailbox, join(',', array_values($msg_ids)));
      else if ($flag=='UNFLAGGED')
        $result = iil_C_UnFlag($this->conn, $this->mailbox, join(',', array_values($msg_ids)), 'FLAGGED');
      else
        $result = iil_C_Flag($this->conn, $this->mailbox, join(',', array_values($msg_ids)), $flag);
      }
    foreach ($uids as $uid) {
      $msg_ids[$uid] = $this->_uid2id($uid);
    }
    if ($flag=='UNDELETED')
      $result = iil_C_Undelete($this->conn, $this->mailbox, join(',', array_values($msg_ids)));
    else if ($flag=='UNSEEN')
      $result = iil_C_Unseen($this->conn, $this->mailbox, join(',', array_values($msg_ids)));
    else if ($flag=='UNFLAGGED')
      $result = iil_C_UnFlag($this->conn, $this->mailbox, join(',', array_values($msg_ids)), 'FLAGGED');
    else
      $result = iil_C_Flag($this->conn, $this->mailbox, join(',', array_values($msg_ids)), $flag);
    // reload message headers if cached
    if ($this->caching_enabled) {
      $cache_key = $this->mailbox.'.msg';
      foreach ($msg_ids as $uid => $id) {
    $cache_key = $this->mailbox.'.msg';
    if ($this->caching_enabled)
      {
      foreach ($msg_ids as $uid => $id)
        {
        if ($cached_headers = $this->get_cached_message($cache_key, $uid))
          {
          $this->remove_message_cache($cache_key, $id);
@@ -1547,7 +1546,7 @@
      }
    // set nr of messages that were flaged
    $count = count($uids);
    $count = count($msg_ids);
    // clear message count cache
    if ($result && $flag=='SEEN')
@@ -2940,9 +2939,9 @@
        }
        
      if (empty($result[$key]['name']))
        $result[$key]['name'] = $result[$key]['address'];
      elseif (empty($result[$key]['address']))
   $result[$key]['address'] = $result[$key]['name'];
        $result[$key]['name'] = $result[$key]['address'];
      elseif (empty($result[$key]['address']))
        $result[$key]['address'] = $result[$key]['name'];
      }
    
    return $result;