示例#1
0
 /**
  * Set message flag to one or several messages
  *
  * @param mixed  Message UIDs as array or as comma-separated string
  * @param string Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT
  * @param string Folder name
  * @param boolean True to skip message cache clean up
  * @return boolean True on success, False on failure
  */
 function set_flag($uids, $flag, $mbox_name = NULL, $skip_cache = false)
 {
     $mailbox = $mbox_name ? $this->mod_mailbox($mbox_name) : $this->mailbox;
     $flag = strtoupper($flag);
     if (!is_array($uids)) {
         $uids = explode(',', $uids);
     }
     if (strpos($flag, 'UN') === 0) {
         $result = iil_C_UnFlag($this->conn, $mailbox, join(',', $uids), substr($flag, 2));
     } else {
         $result = iil_C_Flag($this->conn, $mailbox, join(',', $uids), $flag);
     }
     // reload message headers if cached
     if ($this->caching_enabled && !$skip_cache) {
         $cache_key = $mailbox . '.msg';
         $this->remove_message_cache($cache_key, $uids);
     }
     // set nr of messages that were flaged
     $count = count($uids);
     // clear message count cache
     if ($result && $flag == 'SEEN') {
         $this->_set_messagecount($mailbox, 'UNSEEN', $count * -1);
     } else {
         if ($result && $flag == 'UNSEEN') {
             $this->_set_messagecount($mailbox, 'UNSEEN', $count);
         } else {
             if ($result && $flag == 'DELETED') {
                 $this->_set_messagecount($mailbox, 'ALL', $count * -1);
             }
         }
     }
     return $result;
 }
示例#2
0
 /**
  * Set message flag to one or several messages
  *
  * @param mixed  Message UIDs as array or as comma-separated string
  * @param string Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT
  * @return boolean True on success, False on failure
  */
 function set_flag($uids, $flag)
 {
     $flag = strtoupper($flag);
     $msg_ids = array();
     if (!is_array($uids)) {
         $uids = explode(',', $uids);
     }
     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
     $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);
                 //$this->get_headers($uid);
             }
         }
         // close and re-open connection
         // this prevents connection problems with Courier
         $this->reconnect();
     }
     // set nr of messages that were flaged
     $count = count($msg_ids);
     // clear message count cache
     if ($result && $flag == 'SEEN') {
         $this->_set_messagecount($this->mailbox, 'UNSEEN', $count * -1);
     } else {
         if ($result && $flag == 'UNSEEN') {
             $this->_set_messagecount($this->mailbox, 'UNSEEN', $count);
         } else {
             if ($result && $flag == 'DELETED') {
                 $this->_set_messagecount($this->mailbox, 'ALL', $count * -1);
             }
         }
     }
     return $result;
 }