Changeset 5030 in subversion


Ignore:
Timestamp:
Aug 8, 2011 12:56:33 PM (22 months ago)
Author:
alec
Message:
  • Don't remove cached message on set flag, some small fixes/improvements
Location:
branches/devel-mcache/roundcubemail
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-mcache/roundcubemail/SQL/mysql.initial.sql

    r5028 r5030  
    4646   REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE, 
    4747 INDEX `changed_index` (`changed`), 
    48  PRIMARY KEY (`user_id`, `mailbox`, `sort_field`, `threaded`) 
     48 PRIMARY KEY (`user_id`, `mailbox`, `threaded`, `sort_field`) 
    4949) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; 
    5050 
     
    5858 `changed` datetime NOT NULL DEFAULT '1000-01-01 00:00:00', 
    5959 `data` text, 
     60 `seen` tinyint(1) NOT NULL DEFAULT '0', 
     61 `deleted` tinyint(1) NOT NULL DEFAULT '0', 
     62 `answered` tinyint(1) NOT NULL DEFAULT '0', 
     63 `forwarded` tinyint(1) NOT NULL DEFAULT '0', 
     64 `flagged` tinyint(1) NOT NULL DEFAULT '0', 
     65 `mdnsent` tinyint(1) NOT NULL DEFAULT '0', 
    6066 CONSTRAINT `user_id_fk_cache_messages` FOREIGN KEY (`user_id`) 
    6167   REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE, 
  • branches/devel-mcache/roundcubemail/program/include/rcube_imap.php

    r5029 r5030  
    24722472            // @TODO: update flags instead removing from cache 
    24732473            if (!$skip_cache && ($mcache = $this->get_mcache_engine())) { 
    2474                 $mcache->clear($mailbox, $all_mode ? null : explode(',', $uids)); 
     2474                $status = strpos($flag, 'UN') !== 0; 
     2475                $mflag  = preg_replace('/^UN/', '', $flag); 
     2476                $mcache->change_flag($mailbox, $all_mode ? null : explode(',', $uids), 
     2477                    $mflag, $status); 
    24752478            } 
    24762479 
     
    26042607                    $this->refresh_search(); 
    26052608                else { 
    2606                     $uids = explode(',', $uids); 
    2607                     foreach ($uids as $uid) 
     2609                    $a_uids = explode(',', $uids); 
     2610                    foreach ($a_uids as $uid) 
    26082611                        $a_mids[] = $this->uid2id($uid, $from_mbox); 
    26092612                    $this->search_set = array_diff($this->search_set, $a_mids); 
    26102613                } 
     2614                unset($a_mids); 
     2615                unset($a_uids); 
    26112616            } 
    26122617 
    26132618            // remove cached messages 
    26142619            // @TODO: do cache update instead of clearing it 
    2615             $this->clear_message_cache($from_mbox, $all_mode ? null : $uids); 
     2620            $this->clear_message_cache($from_mbox, $all_mode ? null : explode(',', $uids)); 
    26162621        } 
    26172622 
     
    26982703                    $this->refresh_search(); 
    26992704                else { 
    2700                     $uids = explode(',', $uids); 
    2701                     foreach ($uids as $uid) 
     2705                    $a_uids = explode(',', $uids); 
     2706                    foreach ($a_uids as $uid) 
    27022707                        $a_mids[] = $this->uid2id($uid, $mailbox); 
    27032708                    $this->search_set = array_diff($this->search_set, $a_mids); 
     2709                    unset($a_uids); 
     2710                    unset($a_mids); 
    27042711                } 
    27052712            } 
    27062713 
    27072714            // remove cached messages 
    2708             $this->clear_message_cache($mailbox, $all_mode ? null : $uids); 
     2715            $this->clear_message_cache($mailbox, $all_mode ? null : explode(',', $uids)); 
    27092716        } 
    27102717 
     
    27742781    { 
    27752782        if ($uids && $this->get_capability('UIDPLUS')) 
    2776             $a_uids = is_array($uids) ? join(',', $uids) : $uids; 
     2783            list($uids, $all_mode) = $this->_parse_uids($uids, $mailbox); 
    27772784        else 
    2778             $a_uids = NULL; 
     2785            $uids = null; 
    27792786 
    27802787        // force mailbox selection and check if mailbox is writeable 
     
    27912798 
    27922799        // CLOSE(+SELECT) should be faster than EXPUNGE 
    2793         if (empty($a_uids) || $a_uids == '1:*') 
     2800        if (empty($uids) || $all_mode) 
    27942801            $result = $this->conn->close(); 
    27952802        else 
    2796             $result = $this->conn->expunge($mailbox, $a_uids); 
     2803            $result = $this->conn->expunge($mailbox, $uids); 
    27972804 
    27982805        if ($result && $clear_cache) { 
    2799             // @TODO: I'm not sure we should remove all messages 
    2800             // maybe we could clear only indexes and counters 
    2801             $this->clear_message_cache($mailbox); 
     2806            $this->clear_message_cache($mailbox, $all_mode ? null : explode(',', $uids)); 
    28022807            $this->_clear_messagecount($mailbox); 
    28032808        } 
     
    31613166                    $this->conn->subscribe(preg_replace('/^'.preg_quote($mailbox, '/').'/', 
    31623167                        $new_name, $c_subscribed)); 
     3168 
     3169                    // clear cache 
     3170                    $this->clear_message_cache($c_subscribed); 
    31633171                } 
    31643172            } 
    31653173 
    31663174            // clear cache 
    3167             // @TODO: we could be much smarter here 
    31683175            $this->clear_message_cache($mailbox); 
    31693176            $this->clear_cache('mailboxes', true); 
     
    38403847    function clear_message_cache($mailbox = null, $uids = null) 
    38413848    { 
    3842         if ($mcache = $this->get_cache_engine()) { 
     3849        if ($mcache = $this->get_mcache_engine()) { 
    38433850            $mcache->clear($mailbox, $uids); 
    38443851        } 
  • branches/devel-mcache/roundcubemail/program/include/rcube_imap_cache.php

    r5029 r5030  
    3737     * @var rcube_imap 
    3838     */ 
    39     public $imap; 
     39    private $imap; 
    4040 
    4141    /** 
     
    6161 
    6262    private $skip_deleted = false; 
     63 
     64    public $flag_fields = array('seen', 'deleted', 'answered', 'forwarded', 'flagged', 'mdnsent'); 
     65 
    6366 
    6467    /** 
     
    284287        } 
    285288 
     289        $flag_fields = implode(', ', array_map(array($this->db, 'quoteIdentifier'), $this->flag_fields)); 
     290 
    286291        // Fetch messages from cache 
    287292        $sql_result = $this->db->query( 
    288             "SELECT uid, data" 
     293            "SELECT uid, data, ".$flag_fields 
    289294            ." FROM ".get_table_name('cache_messages') 
    290295            ." WHERE user_id = ?" 
     
    298303        while ($sql_arr = $this->db->fetch_assoc($sql_result)) { 
    299304            $uid          = intval($sql_arr['uid']); 
    300             $result[$uid] = $this->db->decode(unserialize($sql_arr['data'])); 
     305            $result[$uid] = $this->build_message($sql_arr); 
    301306//@TODO: update message ID according to index data? 
    302307 
     
    333338    function get_message($mailbox, $uid) 
    334339    { 
     340        $flag_fields = implode(', ', array_map(array($this->db, 'quoteIdentifier'), $this->flag_fields)); 
     341 
    335342        $sql_result = $this->db->query( 
    336             "SELECT data FROM ".get_table_name('cache_messages') 
     343            "SELECT data, ".$flag_fields 
     344            ." FROM ".get_table_name('cache_messages') 
    337345            ." WHERE user_id = ?" 
    338346                ." AND mailbox = ?" 
    339347                ." AND uid = ?", 
    340                 $this->userid, $mailbox, $uid); 
     348                $this->userid, $mailbox, (int)$uid); 
    341349 
    342350        if ($sql_arr = $this->db->fetch_assoc($sql_result)) { 
    343             $message = $this->db->decode(unserialize($sql_arr['data'])); 
     351            $message = $this->build_message($sql_arr); 
    344352            $found   = true; 
    345353 
     
    372380        $msg = serialize($this->db->encode(clone $message)); 
    373381 
     382        $flag_fields = array_map(array($this->db, 'quoteIdentifier'), $this->flag_fields); 
     383        $flag_values = array(); 
     384 
     385        foreach ($this->flag_fields as $flag) 
     386            $flag_values[] = (int) $message->$flag; 
     387 
    374388        // update cache record (even if it exists, the update 
    375389        // here will work as select, assume row exist if affected_rows=0) 
    376390        if (!$force) { 
     391            foreach ($flag_fields as $key => $val) 
     392                $flag_data[] = $val . " = " . $flag_values[$key]; 
     393 
    377394            $res = $this->db->query( 
    378395                "UPDATE ".get_table_name('cache_messages') 
    379396                ." SET data = ?, changed = ".$this->db->now() 
     397                .", " . implode(', ', $flag_data) 
    380398                ." WHERE user_id = ?" 
    381399                    ." AND mailbox = ?" 
    382400                    ." AND uid = ?", 
    383                 $msg, $this->userid, $mailbox, $message->uid); 
     401                $msg, $this->userid, $mailbox, (int) $message->uid); 
    384402 
    385403            if ($this->db->affected_rows()) 
     
    390408        $this->db->query( 
    391409            "INSERT INTO ".get_table_name('cache_messages') 
    392             ." (user_id, mailbox, uid, changed, data)" 
    393             ." VALUES (?, ?, ?, ".$this->db->now().", ?)", 
    394             $this->userid, $mailbox, $message->uid, $msg); 
    395     } 
    396  
    397  
    398     /** 
    399      * Clears messages/index cache 
     410            ." (user_id, mailbox, uid, changed, data, " . implode(', ', $flag_fields) . ")" 
     411            ." VALUES (?, ?, ?, ".$this->db->now().", ?, " . implode(', ', $flag_values) . ")", 
     412            $this->userid, $mailbox, (int) $message->uid, $msg); 
     413    } 
     414 
     415 
     416    /** 
     417     * Sets the flag for specified message. 
     418     * 
     419     * @param string  $mailbox  Folder name 
     420     * @param array   $uids     Message UIDs or -1 to change flag 
     421     *                          of all messages in a folder 
     422     * @param string  $flag     The name of the flag 
     423     * @param bool    $enabled  Flag state 
     424     */ 
     425    function change_flag($mailbox, $uids, $flag, $enabled = false) 
     426    { 
     427        $flag = strtolower($flag); 
     428 
     429        if (in_array($flag, $this->flag_fields)) { 
     430            $this->db->query( 
     431                "UPDATE ".get_table_name('cache_messages') 
     432                ." SET changed = ".$this->db->now() 
     433                .", " .$this->db->quoteIdentifier($flag) . " = " . intval($enabled) 
     434                ." WHERE user_id = ?" 
     435                    ." AND mailbox = ?" 
     436                    .($uids !== null ? " AND uid IN (".$this->db->array2list((array)$uids, 'integer').")" : ""), 
     437                $this->userid, $mailbox); 
     438        } 
     439        else { 
     440            // @TODO: SELECT+UPDATE? 
     441            $this->remove_message($mailbox, $uids); 
     442        } 
     443    } 
     444 
     445 
     446    /** 
     447     * Removes message(s) from cache. 
    400448     * 
    401449     * @param string $mailbox  Folder name 
    402      * @param array  $uids     Message UIDs 
    403      */ 
    404     function clear($mailbox = null, $uids = array()) 
     450     * @param array  $uids     Message UIDs, NULL removes all messages 
     451     */ 
     452    function remove_message($mailbox = null, $uids = null) 
     453    { 
     454        if (!strlen($mailbox)) { 
     455            $this->db->query( 
     456                "DELETE FROM ".get_table_name('cache_messages') 
     457                ." WHERE user_id = ?", 
     458                $this->userid); 
     459        } 
     460        else { 
     461            $this->db->query( 
     462                "DELETE FROM ".get_table_name('cache_messages') 
     463                ." WHERE user_id = ?" 
     464                    ." AND mailbox = ".$this->db->quote($mailbox) 
     465                    .($uids !== null ? " AND uid IN (".$this->db->array2list((array)$uids, 'integer').")" : ""), 
     466                $this->userid); 
     467        } 
     468 
     469    } 
     470 
     471 
     472    /** 
     473     * Clears messages/index cache. 
     474     * 
     475     * @param string $mailbox  Folder name 
     476     * @param array  $uids     Message UIDs, NULL removes all messages in a folder 
     477     */ 
     478    function clear($mailbox = null, $uids = null) 
    405479    { 
    406480        $this->db->query( 
     
    410484            $this->userid); 
    411485 
    412         if (!strlen($mailbox)) { 
     486        $this->remove_message($mailbox, $uids); 
     487 
     488        if (strlen($mailbox)) 
    413489            unset($this->icache[$mailbox]); 
    414             $this->db->query( 
    415                 "DELETE FROM ".get_table_name('cache_messages') 
    416                 ." WHERE user_id = ?", 
    417                 $this->userid); 
    418         } 
    419         else { 
     490        else 
    420491            $this->icache = array(); 
    421             $this->db->query( 
    422                 "DELETE FROM ".get_table_name('cache_messages') 
    423                 ." WHERE user_id = ?" 
    424                     ." AND mailbox = ".$this->db->quote($mailbox) 
    425                     .(!empty($uids) ? " AND uid IN (".$this->db->array2list($uids, 'integer').")" : ""), 
    426                 $this->userid); 
    427         } 
    428492    } 
    429493 
     
    503567    } 
    504568 
     569 
     570    /** 
     571     * 
     572     */ 
     573    private function build_message($sql_arr) 
     574    { 
     575        $message = $this->db->decode(unserialize($sql_arr['data'])); 
     576 
     577        if ($message) { 
     578            foreach ($this->flag_fields as $field) 
     579                $message->$field = (bool) $sql_arr[$field]; 
     580        } 
     581 
     582        return $message; 
     583    } 
     584 
    505585} 
  • branches/devel-mcache/roundcubemail/program/include/rcube_imap_generic.php

    r5029 r5030  
    4949    public $charset; 
    5050    public $ctype; 
    51     public $flags; 
    5251    public $timestamp; 
    5352    public $body_structure; 
     
    5655    public $priority; 
    5756    public $mdn_to; 
    58     public $mdn_sent = false; 
     57 
     58    public $flags; 
     59    public $mdnsent = false; 
    5960    public $seen = false; 
    6061    public $deleted = false; 
     
    17211722                    foreach ($flags_a as $flag) { 
    17221723                        $flag = str_replace('\\', '', $flag); 
    1723                         $result[$id]->flags[] = $flag; 
    17241724 
    17251725                        switch (strtoupper($flag)) { 
     
    17371737                            break; 
    17381738                        case '$MDNSENT': 
    1739                             $result[$id]->mdn_sent = true; 
     1739                            $result[$id]->mdnsent = true; 
    17401740                            break; 
    17411741                        case 'FLAGGED': 
    17421742                            $result[$id]->flagged = true; 
     1743                            break; 
     1744                        default: 
     1745                            $result[$id]->flags[] = $flag; 
    17431746                            break; 
    17441747                        } 
  • branches/devel-mcache/roundcubemail/program/steps/mail/func.inc

    r4977 r5030  
    14521452    $message = new rcube_message($message); 
    14531453 
    1454   if ($message->headers->mdn_to && !$message->headers->mdn_sent && 
     1454  if ($message->headers->mdn_to && !$message->headers->mdnsent && 
    14551455    ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*'))) 
    14561456  { 
  • branches/devel-mcache/roundcubemail/program/steps/mail/show.inc

    r4802 r5030  
    7474  // check for unset disposition notification 
    7575  if ($MESSAGE->headers->mdn_to && 
    76       !$MESSAGE->headers->mdn_sent && !$MESSAGE->headers->seen && 
     76      !$MESSAGE->headers->mdnsent && !$MESSAGE->headers->seen && 
    7777      ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*')) && 
    7878      $mbox_name != $CONFIG['drafts_mbox'] && 
Note: See TracChangeset for help on using the changeset viewer.