From 3ebac0167bf20104fb7a2a55934765117760264c Mon Sep 17 00:00:00 2001 From: Thomas Bruederli <thomas@roundcube.net> Date: Mon, 18 Aug 2014 03:53:18 -0400 Subject: [PATCH] Only add zen-mode text labels in compose step --- program/lib/Roundcube/rcube_imap_cache.php | 132 ++++++++++++++++++++++++++++++-------------- 1 files changed, 90 insertions(+), 42 deletions(-) diff --git a/program/lib/Roundcube/rcube_imap_cache.php b/program/lib/Roundcube/rcube_imap_cache.php index d72bfe0..e49e778 100644 --- a/program/lib/Roundcube/rcube_imap_cache.php +++ b/program/lib/Roundcube/rcube_imap_cache.php @@ -27,6 +27,9 @@ */ class rcube_imap_cache { + const MODE_INDEX = 1; + const MODE_MESSAGE = 2; + /** * Instance of rcube_imap * @@ -70,6 +73,7 @@ private $icache = array(); private $skip_deleted = false; + private $mode; /** * List of known flags. Thanks to this we can handle flag changes @@ -95,6 +99,7 @@ ); + /** * Object constructor. * @@ -117,6 +122,9 @@ $this->skip_deleted = $skip_deleted; $this->ttl = $ttl; $this->threshold = $threshold; + + // cache all possible information by default + $this->mode = self::MODE_INDEX | self::MODE_MESSAGE; } @@ -127,6 +135,17 @@ { $this->save_icache(); $this->icache = null; + } + + + /** + * Set cache mode + * + * @param int $mode Cache mode + */ + public function set_mode($mode) + { + $this->mode = $mode; } @@ -152,7 +171,7 @@ // Seek in internal cache if (array_key_exists('index', $this->icache[$mailbox])) { // The index was fetched from database already, but not validated yet - if (!array_key_exists('object', $this->icache[$mailbox]['index'])) { + if (empty($this->icache[$mailbox]['index']['validated'])) { $index = $this->icache[$mailbox]['index']; } // We've got a valid index @@ -229,6 +248,7 @@ } $this->icache[$mailbox]['index'] = array( + 'validated' => true, 'object' => $data, 'sort_field' => $sort_field, 'modseq' => !empty($index['modseq']) ? $index['modseq'] : $mbox_data['HIGHESTMODSEQ'] @@ -308,38 +328,46 @@ return array(); } - // Fetch messages from cache - $sql_result = $this->db->query( - "SELECT uid, data, flags" - ." FROM ".$this->db->table_name('cache_messages') - ." WHERE user_id = ?" - ." AND mailbox = ?" - ." AND uid IN (".$this->db->array2list($msgs, 'integer').")", - $this->userid, $mailbox); - - $msgs = array_flip($msgs); $result = array(); - while ($sql_arr = $this->db->fetch_assoc($sql_result)) { - $uid = intval($sql_arr['uid']); - $result[$uid] = $this->build_message($sql_arr); + if ($this->mode & self::MODE_MESSAGE) { + // Fetch messages from cache + $sql_result = $this->db->query( + "SELECT uid, data, flags" + ." FROM ".$this->db->table_name('cache_messages') + ." WHERE user_id = ?" + ." AND mailbox = ?" + ." AND uid IN (".$this->db->array2list($msgs, 'integer').")", + $this->userid, $mailbox); - if (!empty($result[$uid])) { - // save memory, we don't need message body here (?) - $result[$uid]->body = null; + $msgs = array_flip($msgs); - unset($msgs[$uid]); + while ($sql_arr = $this->db->fetch_assoc($sql_result)) { + $uid = intval($sql_arr['uid']); + $result[$uid] = $this->build_message($sql_arr); + + if (!empty($result[$uid])) { + // save memory, we don't need message body here (?) + $result[$uid]->body = null; + + unset($msgs[$uid]); + } } + + $msgs = array_flip($msgs); } // Fetch not found messages from IMAP server if (!empty($msgs)) { - $messages = $this->imap->fetch_headers($mailbox, array_keys($msgs), false, true); + $messages = $this->imap->fetch_headers($mailbox, $msgs, false, true); // Insert to DB and add to result list if (!empty($messages)) { foreach ($messages as $msg) { - $this->add_message($mailbox, $msg, !array_key_exists($msg->uid, $result)); + if ($this->mode & self::MODE_MESSAGE) { + $this->add_message($mailbox, $msg, !array_key_exists($msg->uid, $result)); + } + $result[$msg->uid] = $msg; } } @@ -370,23 +398,29 @@ return $this->icache['__message']['object']; } - $sql_result = $this->db->query( - "SELECT flags, data" - ." FROM ".$this->db->table_name('cache_messages') - ." WHERE user_id = ?" - ." AND mailbox = ?" - ." AND uid = ?", - $this->userid, $mailbox, (int)$uid); + if ($this->mode & self::MODE_MESSAGE) { + $sql_result = $this->db->query( + "SELECT flags, data" + ." FROM ".$this->db->table_name('cache_messages') + ." WHERE user_id = ?" + ." AND mailbox = ?" + ." AND uid = ?", + $this->userid, $mailbox, (int)$uid); - if ($sql_arr = $this->db->fetch_assoc($sql_result)) { - $message = $this->build_message($sql_arr); - $found = true; + if ($sql_arr = $this->db->fetch_assoc($sql_result)) { + $message = $this->build_message($sql_arr); + $found = true; + } } // Get the message from IMAP server if (empty($message) && $update) { $message = $this->imap->get_message_headers($uid, $mailbox, true); // cache will be updated in close(), see below + } + + if (!($this->mode & self::MODE_MESSAGE)) { + return $message; } // Save the message in internal cache, will be written to DB in close() @@ -421,6 +455,10 @@ function add_message($mailbox, $message, $force = false) { if (!is_object($message) || empty($message->uid)) { + return; + } + + if (!($this->mode & self::MODE_MESSAGE)) { return; } @@ -495,6 +533,10 @@ return; } + if (!($this->mode & self::MODE_MESSAGE)) { + return; + } + $flag = strtoupper($flag); $idx = (int) array_search($flag, $this->flags); $uids = (array) $uids; @@ -535,6 +577,10 @@ */ function remove_message($mailbox = null, $uids = null) { + if (!($this->mode & self::MODE_MESSAGE)) { + return; + } + if (!strlen($mailbox)) { $this->db->query( "DELETE FROM ".$this->db->table_name('cache_messages') @@ -845,6 +891,8 @@ return false; } + $index['validated'] = true; + // Get mailbox data (UIDVALIDITY, counters, etc.) for status check $mbox_data = $this->imap->folder_data($mailbox); @@ -1036,15 +1084,17 @@ $removed = array(); // Get known UIDs - $sql_result = $this->db->query( - "SELECT uid" - ." FROM ".$this->db->table_name('cache_messages') - ." WHERE user_id = ?" - ." AND mailbox = ?", - $this->userid, $mailbox); + if ($this->mode & self::MODE_MESSAGE) { + $sql_result = $this->db->query( + "SELECT uid" + ." FROM ".$this->db->table_name('cache_messages') + ." WHERE user_id = ?" + ." AND mailbox = ?", + $this->userid, $mailbox); - while ($sql_arr = $this->db->fetch_assoc($sql_result)) { - $uids[] = $sql_arr['uid']; + while ($sql_arr = $this->db->fetch_assoc($sql_result)) { + $uids[] = $sql_arr['uid']; + } } // Synchronize messages data @@ -1203,10 +1253,8 @@ unset($msg->replaces); - if (is_array($msg->structure->parts)) { - foreach ($msg->structure->parts as $part) { - $this->message_object_prepare($part, $size); - } + if (is_object($msg->structure)) { + $this->message_object_prepare($msg->structure, $size); } if (is_array($msg->parts)) { -- Gitblit v1.9.1