| | |
| | | */ |
| | | // add message to cache |
| | | if ($this->caching_enabled && $cache_index[$headers->id] != $headers->uid) |
| | | $this->add_message_cache($cache_key, $headers->id, $headers); |
| | | $this->add_message_cache($cache_key, $headers->id, $headers, NULL, |
| | | !in_array((string)$headers->uid, $cache_index, true)); |
| | | |
| | | $a_msg_headers[$headers->uid] = $headers; |
| | | } |
| | |
| | | if (!empty($for_update)) { |
| | | if ($headers = iil_C_FetchHeader($this->conn, $mailbox, join(',', $for_update), false, $this->fetch_add_headers)) |
| | | foreach ($headers as $header) |
| | | $this->add_message_cache($cache_key, $header->id, $header); |
| | | $this->add_message_cache($cache_key, $header->id, $header, NULL, |
| | | in_array((string)$header->uid, $for_remove, true)); |
| | | } |
| | | } |
| | | |
| | |
| | | if ($headers->uid && $headers->id) |
| | | $this->uid_id_map[$mailbox][$headers->uid] = $headers->id; |
| | | |
| | | $this->add_message_cache($mailbox.'.msg', $headers->id, $headers); |
| | | $this->add_message_cache($mailbox.'.msg', $headers->id, $headers, NULL, true); |
| | | } |
| | | |
| | | return $headers; |
| | |
| | | function &get_structure($uid, $structure_str='') |
| | | { |
| | | $cache_key = $this->mailbox.'.msg'; |
| | | $headers = &$this->get_cached_message($cache_key, $uid, true); |
| | | $headers = &$this->get_cached_message($cache_key, $uid); |
| | | |
| | | // return cached message structure |
| | | if (is_object($headers) && is_object($headers->structure)) { |
| | |
| | | * @param string Internal cache key |
| | | * @return int -3 = off, -2 = incomplete, -1 = dirty |
| | | */ |
| | | function check_cache_status($mailbox, $cache_key) |
| | | private function check_cache_status($mailbox, $cache_key) |
| | | { |
| | | if (!$this->caching_enabled) |
| | | return -3; |
| | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function get_message_cache($key, $from, $to, $sort_field, $sort_order) |
| | | private function get_message_cache($key, $from, $to, $sort_field, $sort_order) |
| | | { |
| | | $cache_key = "$key:$from:$to:$sort_field:$sort_order"; |
| | | $db_header_fields = array('idx', 'uid', 'subject', 'from', 'to', 'cc', 'date', 'size'); |
| | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function &get_cached_message($key, $uid, $struct=false) |
| | | private function &get_cached_message($key, $uid) |
| | | { |
| | | $internal_key = '__single_msg'; |
| | | |
| | | if ($this->caching_enabled && (!isset($this->cache[$internal_key][$uid]) || |
| | | ($struct && empty($this->cache[$internal_key][$uid]->structure)))) |
| | | { |
| | | $sql_select = "idx, uid, headers" . ($struct ? ", structure" : ''); |
| | | $sql_result = $this->db->query( |
| | | "SELECT $sql_select |
| | | "SELECT idx, headers, structure |
| | | FROM ".get_table_name('messages')." |
| | | WHERE user_id=? |
| | | AND cache_key=? |
| | |
| | | $_SESSION['user_id'], |
| | | $key, |
| | | $uid); |
| | | |
| | | if ($sql_arr = $this->db->fetch_assoc($sql_result)) |
| | | { |
| | | $this->uid_id_map[preg_replace('/\.msg$/', '', $key)][$uid] = $sql_arr['idx']; |
| | | $this->cache[$internal_key][$uid] = $this->db->decode(unserialize($sql_arr['headers'])); |
| | | if (is_object($this->cache[$internal_key][$uid]) && !empty($sql_arr['structure'])) |
| | | $this->cache[$internal_key][$uid]->structure = $this->db->decode(unserialize($sql_arr['structure'])); |
| | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function get_message_cache_index($key, $force=FALSE, $sort_field='idx', $sort_order='ASC') |
| | | private function get_message_cache_index($key, $force=FALSE, $sort_field='idx', $sort_order='ASC') |
| | | { |
| | | static $sa_message_index = array(); |
| | | |
| | |
| | | /** |
| | | * @access private |
| | | */ |
| | | private function add_message_cache($key, $index, $headers, $struct=null) |
| | | private function add_message_cache($key, $index, $headers, $struct=null, $force=false) |
| | | { |
| | | if (empty($key) || !is_object($headers) || empty($headers->uid)) |
| | | return; |
| | | |
| | | // add to internal (fast) cache |
| | | $this->cache['__single_msg'][$headers->uid] = $headers; |
| | | $this->cache['__single_msg'][$headers->uid] = clone $headers; |
| | | $this->cache['__single_msg'][$headers->uid]->structure = $struct; |
| | | |
| | | // no further caching |
| | |
| | | return; |
| | | |
| | | // check for an existing record (probly headers are cached but structure not) |
| | | if (!$force) { |
| | | $sql_result = $this->db->query( |
| | | "SELECT message_id |
| | | FROM ".get_table_name('messages')." |
| | |
| | | $_SESSION['user_id'], |
| | | $key, |
| | | $headers->uid); |
| | | if ($sql_arr = $this->db->fetch_assoc($sql_result)) |
| | | $message_id = $sql_arr['message_id']; |
| | | } |
| | | |
| | | // update cache record |
| | | if ($sql_arr = $this->db->fetch_assoc($sql_result)) |
| | | if ($message_id) |
| | | { |
| | | $this->db->query( |
| | | "UPDATE ".get_table_name('messages')." |
| | |
| | | $index, |
| | | serialize($this->db->encode(clone $headers)), |
| | | is_object($struct) ? serialize($this->db->encode(clone $struct)) : NULL, |
| | | $sql_arr['message_id'] |
| | | $message_id |
| | | ); |
| | | } |
| | | else // insert new record |
| | |
| | | $key, |
| | | $index, |
| | | $headers->uid, |
| | | |
| | | (string)rc_substr($this->db->encode($this->decode_header($headers->subject, TRUE)), 0, 128), |
| | | (string)rc_substr($this->db->encode($this->decode_header($headers->from, TRUE)), 0, 128), |
| | | (string)rc_substr($this->db->encode($this->decode_header($headers->to, TRUE)), 0, 128), |