/**
  * Set message flag to one or several messages
  *
  * @param mixed   $uids       Message UIDs as array or comma-separated string, or '*'
  * @param string  $flag       Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT
  * @param string  $folder    Folder name
  * @param boolean $skip_cache True to skip message cache clean up
  *
  * @return boolean  Operation status
  */
 public function set_flag($uids, $flag, $folder = null, $skip_cache = false)
 {
     if (!strlen($folder)) {
         $folder = $this->folder;
     }
     if (!$this->check_connection()) {
         return false;
     }
     $flag = strtoupper($flag);
     list($uids, $all_mode) = $this->parse_uids($uids);
     if (strpos($flag, 'UN') === 0) {
         $result = $this->conn->unflag($folder, $uids, substr($flag, 2));
     } else {
         $result = $this->conn->flag($folder, $uids, $flag);
     }
     if ($result) {
         // reload message headers if cached
         // @TODO: update flags instead removing from cache
         if (!$skip_cache && ($mcache = $this->get_mcache_engine())) {
             $status = strpos($flag, 'UN') !== 0;
             $mflag = preg_replace('/^UN/', '', $flag);
             $mcache->change_flag($folder, $all_mode ? null : explode(',', $uids), $mflag, $status);
         }
         // clear cached counters
         if ($flag == 'SEEN' || $flag == 'UNSEEN') {
             $this->clear_messagecount($folder, 'SEEN');
             $this->clear_messagecount($folder, 'UNSEEN');
         } else {
             if ($flag == 'DELETED') {
                 $this->clear_messagecount($folder, 'DELETED');
             }
         }
     }
     return $result;
 }
Example #2
0
 /**
  * Set message flag to one or several messages
  *
  * @param mixed   $uids       Message UIDs as array or comma-separated string, or '*'
  * @param string  $flag       Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT
  * @param string  $mbox_name  Folder name
  * @param boolean $skip_cache True to skip message cache clean up
  * @return boolean  Operation status
  */
 function set_flag($uids, $flag, $mbox_name = NULL, $skip_cache = false)
 {
     $mailbox = strlen($mbox_name) ? $this->mod_mailbox($mbox_name) : $this->mailbox;
     $flag = strtoupper($flag);
     list($uids, $all_mode) = $this->_parse_uids($uids, $mailbox);
     if (strpos($flag, 'UN') === 0) {
         $result = $this->conn->unflag($mailbox, $uids, substr($flag, 2));
     } else {
         $result = $this->conn->flag($mailbox, $uids, $flag);
     }
     if ($result) {
         // reload message headers if cached
         if ($this->caching_enabled && !$skip_cache) {
             $cache_key = $mailbox . '.msg';
             if ($all_mode) {
                 $this->clear_message_cache($cache_key);
             } else {
                 $this->remove_message_cache($cache_key, explode(',', $uids));
             }
         }
         // clear cached counters
         if ($flag == 'SEEN' || $flag == 'UNSEEN') {
             $this->_clear_messagecount($mailbox, 'SEEN');
             $this->_clear_messagecount($mailbox, 'UNSEEN');
         } else {
             if ($flag == 'DELETED') {
                 $this->_clear_messagecount($mailbox, 'DELETED');
             }
         }
     }
     return $result;
 }