roundcubemail/program/lib/Roundcube/rcube_imap_cache.php
function change_flag($mailbox, $uids, $flag, $enabled = false)
    {
        if (empty($uids)) {
            return;
        }

        if (!($this->mode & self::MODE_MESSAGE)) {
            return;
        }

        $flag = strtoupper($flag);
        $idx  = (int) array_search($flag, $this->flags);
        $uids = (array) $uids;

        if (!$idx) {
            return;
        }

        // Internal cache update
        if (($message = $this->icache['__message'])
            && $message['mailbox'] === $mailbox
            && in_array($message['object']->uid, $uids)
        ) {
            $message['object']->flags[$flag] = $enabled;

            if (count($uids) == 1) {
                return;
            }
        }

        $binary_check = $this->db->db_provider == 'oracle' ? "BITAND(`flags`, %d)" : "(`flags` & %d)";

        $this->db->query(
            "UPDATE {$this->messages_table}"
            ." SET `expires` = ". ($this->ttl ? $this->db->now($this->ttl) : 'NULL')
            .", `flags` = `flags` ".($enabled ? "+ $idx" : "- $idx")
            ." WHERE `user_id` = ?"
                ." AND `mailbox` = ?"
                .(!empty($uids) ? " AND `uid` IN (".$this->db->array2list($uids, 'integer').")" : "")
                ." AND " . sprintf($binary_check, $idx) . ($enabled ? " = 0" : " = $idx"),
            $this->userid, $mailbox);
    }
function change_flag($mailbox, $uids, $flag, $enabled = false)
    {
        if (empty($uids)) {
            return;
        }

        if (!($this->mode & self::MODE_MESSAGE)) {
            return;
        }

        $flag = strtoupper($flag);
        $idx  = (int) array_search($flag, $this->flags);
        $uids = (array) $uids;

        if (!$idx) {
            return;
        }

        // Internal cache update
        if (($message = $this->icache['__message'])
            && $message['mailbox'] === $mailbox
            && in_array($message['object']->uid, $uids)
        ) {
            $message['object']->flags[$flag] = $enabled;

            if (count($uids) == 1) {
                return;
            }
        }

        $binary_check = $this->db->db_provider == 'oracle' ? "BITAND(`flags`, %d)" : "(`flags` & %d)";

        $this->db->query(
            "UPDATE {$this->messages_table}"
            ." SET `expires` = ". ($this->ttl ? $this->db->now($this->ttl) : 'NULL')
            .", `flags` = `flags` ".($enabled ? "+ $idx" : "- $idx")
            ." WHERE `user_id` = ?"
                ." AND `mailbox` = ?"
                .(!empty($uids) ? " AND `uid` IN (".$this->db->array2list($uids, 'integer').")" : "")
                ." AND " . sprintf($binary_check, $idx) . ($enabled ? " = 0" : " = $idx"),
            $this->userid, $mailbox);
    }
function change_flag ( $ mailbox , $ uids , $ flag , $ enabled = false ) { if ( empty ( $ uids ) ) { return ; } if ( ! ( $ this -> mode & self :: MODE_MESSAGE ) ) { return ; } $ flag = strtoupper ( $ flag ) ; $ idx = ( int ) array_search ( $ flag , $ this -> flags ) ; $ uids = ( array ) $ uids ; if ( ! $ idx ) { return ; } // Internal cache update if ( ( $ message = $ this -> icache [ '__message' ] ) && $ message [ 'mailbox' ] === $ mailbox && in_array ( $ message [ 'object' ] -> uid , $ uids ) ) { $ message [ 'object' ] -> flags [ $ flag ] = $ enabled ; if ( count ( $ uids ) == 1 ) { return ; } } $ binary_check = $ this -> db -> db_provider == 'oracle' ? "BITAND(`flags`, %d)" : "(`flags` & %d)" ; $ this -> db -> query ( "UPDATE {$this->messages_table}" . " SET `expires` = " . ( $ this -> ttl ? $ this -> db -> now ( $ this -> ttl ) : 'NULL' ) . ", `flags` = `flags` " . ( $ enabled ? "+ $idx" : "- $idx" ) . " WHERE `user_id` = ?" . " AND `mailbox` = ?" . ( ! empty ( $ uids ) ? " AND `uid` IN (" . $ this -> db -> array2list ( $ uids , 'integer' ) . ")" : "" ) . " AND " . sprintf ( $ binary_check , $ idx ) . ( $ enabled ? " = 0" : " = $idx" ) , $ this -> userid , $ mailbox ) ; }
Sets the flag for specified message.

@param string  $mailbox  Folder name
@param array   $uids     Message UIDs or null to change flag
of all messages in a folder
@param string  $flag     The name of the flag
@param bool    $enabled  Flag state
Sets the flag for specified message .